Mysql Select Subquery If Exists
I have 3 tables ....users, updates and bumps. I want to return the user making the api request a feed updates in most recent order with all the needed data to display each of the s
Solution 1:
Add a LEFT JOIN to get all those result JOINed to BUMPS and return NULLs if the values are not there
SELECT b.type,
b.owner,
b.update_img,
b.ALBUM_ID,
b.last_comment,
a.uid,
a.first_name,
a.last_name,
a.gender,
a.thumb_img,
b.msg_id,
b.message,
b.created,
b.POST_PRIVACY,
(CASE WHEN bm.MSG_ID_FK IS NOT NULL THEN 1 ELSE NULL END) AS 'isBumpedBool'
FROM users AS a JOIN
updates AS b
ON b.uid_fk = a.uid
AND b.type<>'FRIEND_RELATIONSHIP'
AND b.created<$time
AND b.type<>'FAMILIAR_RELATIONSHIP'
AND a.college='$college'
AND b.POST_PRIVACY<>'4'
AND b.POST_PRIVACY<>'5'
AND b.created>=$tstamp
LEFT JOIN BUMPS as bm
ON b.msg_id= bm.MSG_ID_FK
AND bm.UID_FK=$loggedin_uid
ORDER BY b.created DESC LIMIT 100
Post a Comment for "Mysql Select Subquery If Exists"