同じスキーマを持ち、3つの異なるソースからの同様の結果を含む3つのテーブル(s_place、s_place_bing、s_place_yahoo)があります。私が望むのは、与えられたs_u_id、s_q_idおよび日付と一致する3つのテーブルからすべての結果を返すクエリです。null /空白を返さない複数テーブル結合でのヘルプ
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| s_u_id | int(10) | NO | | NULL | |
| s_q_id | int(10) | NO | | NULL | |
| place | int(10) | NO | | NULL | |
| date | int(10) | YES | | NULL | |
| fullurl | varchar(255) | NO | | NULL | |
| above_today | varchar(255) | NO | | NULL | |
| above_yesterday | varchar(255) | NO | | NULL | |
| below_today | varchar(255) | NO | | NULL | |
| below_yesterday | varchar(255) | NO | | NULL | |
| yesterday | int(11) | NO | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
それは同じs_u_id、s_q_idと日付の他にあるよりも、一つのテーブルでより多くの結果があるだろうということは非常に可能性があります。この場合、データを持たないテーブルに対しては空白の行が返されます。
これまでのところ、以下のクエリを使用していますが、null /空白は返されません。
SELECT s_place.s_u_id, s_place.s_q_id, `s_place`.place as place, `s_place`.fullurl as fullurl, `s_place`.date as date, s_place_bing.place as b_place,`s_place_bing`.fullurl as b_fullurl, s_place_bing.date as b_date, s_place_yahoo.place as y_place, `s_place_yahoo`.fullurl as y_fullurl, s_place_yahoo.date as y_date
from s_place
left join s_place_bing on s_place_bing.s_q_id = s_place.s_q_id and s_place_bing.date = s_place.date
left join s_place_yahoo on s_place_yahoo.s_q_id = s_place.s_q_id and s_place_yahoo.date = s_place.date
where s_place.s_u_id = 1 and s_place.s_q_id = 64
order by s_place.date desc
+--------+--------+-------+----------------------+------------+---------+--------------------------+------------+---------+-------------------+------------+
| s_u_id | s_q_id | place | fullurl | date | b_place | b_fullurl | b_date | y_place | y_fullurl | y_date |
+--------+--------+-------+----------------------+------------+---------+--------------------------+------------+---------+-------------------+------------+
| 1 | 64 | 39 | rrr.co.uk | 1292112000 | 30 | rrr.co.uk | 1292112000 | 6 | rrr.co.uk | 1292112000 |
| 1 | 64 | 39 | rrr.co.uk | 1292112000 | 65 | rrr.co.uk search/ | 1292112000 | 6 | rrr.co.uk | 1292112000 |
| 1 | 64 | 36 | rrr.co.uk | 1292025600 | 30 | rrr.co.uk | 1292025600 | 6 | rrr.co.uk | 1292025600 |
| 1 | 64 | 36 | rrr.co.uk | 1292025600 | 64 | rrr.co.uk search/ | 1292025600 | 6 | rrr.co.uk | 1292025600 |
| 1 | 64 | 40 | rrr.co.uk | 1291939200 | 66 | rrr.co.uk search/ | 1291939200 | 9999 | | 1291939200 |
| 1 | 64 | 40 | rrr.co.uk | 1291939200 | 29 | rrr.co.uk | 1291939200 | 9999 | | 1291939200 |
| 1 | 64 | 38 | rrr.co.uk | 1291852800 | 29 | rrr.co.uk | 1291852800 | 6 | rrr.co.uk | 1291852800 |
| 1 | 64 | 38 | rrr.co.uk | 1291852800 | 68 | rrr.co.uk search/ | 1291852800 | 6 | rrr.co.uk | 1291852800 |
これはデータを返さなければならない方法です。
+--------+--------+-------+----------------------+------------+---------+--------------------------+------------+---------+-------------------+------------+
| s_u_id | s_q_id | place | fullurl | date | b_place | b_fullurl | b_date | y_place | y_fullurl | y_date |
+--------+--------+-------+----------------------+------------+---------+--------------------------+------------+---------+-------------------+------------+
| 1 | 4 | 39 | rrr.co.uk | 1292112000 | 30 | rrr.co.uk | 1292112000 | 6 | rrr.co.uk | 1292112000 |
| 1 | 64 | | | | 65 | rrr.co.uk search/ | 1292112000 | | | |
| 1 | 64 | 36 | rrr.co.uk | 1292025600 | 30 | rrr.co.uk | 1292025600 | 6 | rrr.co.uk | 1292025600 |
| 1 | 64 | | | | 64 | rrr.co.uk search/ | 1292025600 | | | |
| 1 | 64 | 40 | rrr.co.uk | 1291939200 | 66 | rrr.co.uk search/ | 1291939200 | 9999 | | 1291939200 |
| 1 | 64 | | | | 29 | rrr.co.uk | 1291939200 | | | |
| 1 | 64 | 38 | rrr.co.uk | 1291852800 | 29 | rrr.co.uk | 1291852800 | 6 | rrr.co.uk | 1291852800 |
| 1 | 64 | | | | 68 | rrr.co.uk search/ | 1291852800 | | | |
誰かが助けてくれることを願っています。乾杯、