0

Ok I want to join two tables typespayment and income so I tried to to a LEFT JOIN like this

SELECT
    typespayment.name AS payment_name,
    income.amount,
    income.idUser
FROM
    typespayment
LEFT JOIN income ON income.idTypePayment = typespayment.id
WHERE
    income.idUser = 2

but I get this

+---------------+------------+--------+
| payment_name  |  amount    | idUser |
+---------------+------------+--------+
| Transfer      | 3000.00    |      2 |
+---------------+------------+--------+

But I excepected non matching row too with null value like this. I want to retrive non matching value to

+---------------+------------+--------+
| payment_name  |  amount    | idUser |
+---------------+------------+--------+
| Transfer      | 3000.00    | 2      |
| cash          |  null      | null   |
| c-card        | nulll      | null   |
+---------------+------------+--------+

How I can join these two tables with matching data and non matching data, I just want to display that there are other types of payments that the user doesn't user. What Im doing wrong. I choose left join because this diagram left join Watch the following tables:

typespayment

+----+----------+
| id |   name   |
+----+----------+
|  1 | cash     |
|  2 | c-card   |
|  3 | transfer |
+----+----------+
income table

+----+---------+--------+---------------+--------+--+
| id | concept | amount | idTypePayment | idUser |  |
+----+---------+--------+---------------+--------+--+
|  1 | Food    |    300 |             1 |      1 |  |
|  2 | Fixes   |    400 |             3 |      2 |  |
|  3 | Dentist |    500 |             2 |      3 |  |
+----+---------+--------+---------------+--------+--+
Users
+----+---------+
| id |  name   |
+----+---------+
|  1 | Paul    |
|  2 | Jackson |
|  3 | Peter   |
+----+---------+

0 Answers0