php - There are 3 tables users,winks and favourite -
there 3 table please @ structure
users table
====================== id(users.id) |username | status ---------------------------------- 56 | mark | 1 ---------------------------------- 57 | john | 1 ---------------------------------- 58 | lina | 1 ---------------------------------- 59 | lara | 1 ----------------------------------
winks table
====================== wink_id | from_id(fk users.id) | to_id(fk user.id) | wink_flag -------------------------------------------------------------------------- 1 | 56 | 57 | 1 -------------------------------------------------------------------------- 2 | 56 | 58 | 1 --------------------------------------------------------------------------
favourite table
====================== fav_id | from_id(fk user.id) | to_id(fk user.id) | fav_flag ------------------------------------------------------------------------ 1 | 56 | 59 | 1 ------------------------------------------------------------------------ 1 | 56 | 58 | 1 ------------------------------------------------------------------------
want left join have data this.
======================================================================= id | wink_flag | fav_flg | status ------------------------------------ 57 | 1 | null ------------------------------------ 58 | 1 | 1 ------------------------------------ 59 | null | 1 ------------------------------------
i joining 2 table winks , fav using left join users
- query
when result comes user.id <> 56
means when logged in using 56 user.id
then have users row except me here take logged in 56 user.id
result this.
====================================== id | wink_flag | fav_flg | status ------------------------------------ 57 | 1 | null ------------------------------------ 58 | 1 | 1 ------------------------------------ 59 | null | 1 ------------------------------------
how can write sql query have above result.
help me.
without left join
see demo sql fiddle
select u.id, (select w.wink_flag winks w w.to_id = u.id group w.to_id) wink_flag, (select f.fav_flag favourite f f.to_id = u.id group f.to_id) fav_flag users u u.id != 56
Comments
Post a Comment