[TABLE1]
+----------+-------------------+-------------+
| USERNAME | POST | FRUIT |
+----------+-------------------+-------------+
| Bob | 'Hi There' | APPLE |
| Jack | 'Hello' | ORANGE |
| Bob | 'Today is Monday' | APPLE |
| Tony | 'That is ok' | PEAR |
+----------+-------------------+-------------+
[TABLE2]
+----------+-----------+
| USERNAME | FOLLOWING |
+----------+-----------+
| Mike | Jack |
| Jack | Bob |
| Bob | Jack |
| Jack | Mike |
+----------+-----------+
[TABLE3]
+----------+----------- +
| USERNAME | LIKESFRUIT |
+----------+----------- +
| Mike | APPLE |
| Jack | ORANGE |
| Bob | BERRY |
| Jack | PEAR |
+----------+------------+
我正在使用下面的查詢。這表明,如果插孔以下表2中的用戶或插孔中的用戶名在表1mysql內部連接需要另一種連接類型
SELECT t1.*
FROM TABLE1 t1
INNER JOIN table2 t2
ON t1.username = t2.following
AND (t2.username = 'jack' OR t1.username = 'jack');
現在我想做到這一點,顯示如果傑克LIKESFRUIT表3中從TABLE1記錄FROM表1中的所有記錄。
你是什麼意思「*顯示從TABLE1記錄,如果平均... *「?你的意思是如果條件滿足,則從'TABLE1'返回所有記錄?或者是其他東西? – eggyal 2012-07-23 11:26:43
提供預期結果 – Madhivanan 2012-07-23 11:28:25
我的解決方案是否適合您? – 2012-07-23 13:00:27