Hi friends I have 3 table topups, withdraws and transfers these 3 tables belongs to the user table. I have to find all the records which belongs to the users. I tried with inner join as follows:-
SELECT * FROM users u
INNER JOIN topups t
ON u.id = t.user_id
INNER JOIN withdraws w
ON u.id = w.user_id
INNER JOIN transfers tf
ON u.id = tf.user_id
But this query returns only the common records between the 3 tables. i have to find all those records which belongs to the user for each table.
Suppose i have 2 records in topups which belongs to user id 1, 3 records in withdraws which belongs to user id 2 and 5 records in transfers which belongs to user id 3 so i should get the total 10 records.
sample data:-
topups
+--------+---------+---------+
| amount | result | user_id |
+--------+---------+---------+
| 10 | success | 1 |
| 20 | failed | 2 |
+--------+---------+---------+
withdraws
+---------+----------+
|w_amount | user_id |
+---------+----------+
| 10 | 1 |
| 20 | 2 |
| 30 | 10 |
+---------+----------+
Transfers
+--------+--------+---------+
| method | amount | user_id |
+--------+--------+---------+
| abc | 10 | 3 |
| xyz | 20 | 4 |
+--------+--------+---------+
users
+----+---------+--------+
| id | f_name | l_name |
+----+---------+--------+
| 1 | abc | xyz |
| 2 | abc | xyz |
| 3 | abc | xyz |
| 4 | abc | xyz |
| 5 | abc | xyz |
| 6 | abc | xyz |
+----+---------+--------+
Expected output
+--------+---------+---------+----------+---------+
| amount | result | user_id | w_amount | method |
+--------+---------+---------+----------+---------+
| 10 | success | 1 | | |
| 20 | failed | 2 | | |
| | | 1 | 10 | |
| | | 2 | 20 | |
| | | 3 | | abc |
| | | 4 | | xyz |
+--------+---------+---------+----------+---------+
Please help Thanks in advance.