Reputation: 227
I have user
table and payment
is many to many relationships table.
SELECT user.uID,
user.uName,
user.uLocation,
user.uBlock,
user.uRoom,
user.uStatus,
payment.pID,
payment.pDate,
payment.pType
FROM user
INNER JOIN payment
ON user.uID = payment.pID
LIMIT 0,100
INNER JOIN
results will be nothing.LEFT JOIN
user display correct result but return NULL
on payment tableRIGHT JOIN
payment display correct result but return NULL
on user tableHow do I get a correct result to display both? LEFT JOIN
& RIGHT JOIN
Upvotes: 0
Views: 48
Reputation: 150253
Do you want FULL OUTER JOIN
?
SELECT user.uID,
user.uName,
user.uLocation,
user.uBlock,
user.uRoom,
user.uStatus,
payment.pID,
payment.pDate,
payment.pType
FROM user
FULL OUTER JOIN payment
ON user.uID = payment.pID
LIMIT 0,100
Full outer join
Conceptually, a full outer join combines the effect of applying both left and right outer joins. Where records in the FULL OUTER JOINed tables do not match, the result set will have NULL values for every column of the table that lacks a matching row. For those records that do match, a single row will be produced in the result set (containing fields populated from both tables).
For MySQL
read this, you should use UNION
Upvotes: 2
Reputation: 238068
You're demanding that user id equals payment id. You're lucky if that returns an empty set, it could also return completely wrong data :) It should probably be:
user.uID = payment.uID
Or payment.userId
, or something. Check the columns in the payments table.
Upvotes: 1