2017-09-27 105 views
0

這是這些查詢中的myquery,我使用inner join從4個表中獲取結果。它返回從4個表中匹配的所有記錄。 但我想也得到那些在fl_customer_profile表和fl_users表中匹配的reords。並且還得到那些id在4個表中匹配的記錄。sql內部連接查詢

SELECT u.*,c.*,s.*,p.* 
FROM fl_users u 
INNER JOIN fl_customer_profile c 
    on u.id = c.userID 
INNER JOIN fl_customer_subscription s 
    on u.id = s.userid 
INNER JOIN fl_subscription p 
    on s.planId = p.id 

fl_users表

ID 
| 879 | 

| 884 | 

fl_customer_profile表

userID 
| 879 | 

| 884 | 
+0

請粘貼表 – iamsankalp89

回答

0

我猜你正在試圖讓所有fl_customer_profile匹配的記錄和fl_users是否存在於其他表與否,如果內連接存在於兩個表中,則內連接將返回記錄,而左連接將返回左表中的所有記錄,而第二個表中將只返回匹配的行

SELECT u.*,c.*,s.*,p.* 
FROM fl_users u 
INNER JOIN fl_customer_profile c 
    on u.id = c.userID 
LEFT JOIN fl_customer_subscription s 
    on u.id = s.userid 
LEFT JOIN fl_subscription p 
    on s.planId = p.id 
+0

感謝您的這些解決方案 –