我正在爲我的網頁做搜索,我面臨一個小問題,我想從兩個非關係表中獲取信息,但數據沒有返回我的方式要關於seacher的兩個非關係表的SQL語句
表1
ID |FNAME |LNAME | STATE | CITY
------------------------------
1 |xxxxx1 |xxxxx1| xxxx1 | xx1
2 |xxxxx2 |xxxxx2| toronto| xx2
3 |xxxxx3 |xxxxx3| xxxx3 | yy3
4 |zzzzz3 |zzzzz3| toronto| yy3
表2
ID |NAME | STATE | CITY
---------------------
1 |yyyyy1 | yyyy1 | yy1
2 |yyyyy2 | yyyy2 | yy2
3 |yyyyy3 | toronto| yy3
目前
我哈已經
SELECT
e.id_client, e.fname_client, e.city_client, e.state_client , m.id_client, m.fname_client, m.lname_client, m.state_client, m.city_client
FROM
empresas e
CROSS JOIN
medicos m
WHERE
e.fname_client LIKE :busqueda
OR
e.city_client LIKE :busqueda
OR
m.fname_client LIKE :busqueda
OR
m.lname_client LIKE :busqueda
OR
m.state_client LIKE :busqueda
OR
m.city_client LIKE :busqueda
這顯示這樣
ID| FNAME |LNAME | STATE | CITY |ID|FNAME |LNAME | STATE | CITY
3 |yyyyy3 | | yyyy3 | yy3 |3 |xxxxx3 |xxxxx3| xxxx3 | yy3
的結果,但我希望它這樣
ID|FNAME |LNAME | STATE | CITY
3 |xxxxx3 |xxxxx3| xxxx3 | yy3
3 |yyyyy3 | | yyyy3 | yy3
編輯:
與UNION asnwer我得到的數據我想要的格式,但是當我搜索公共值時只顯示一個表格的結果,例如:
如果鍵入「多倫多」,這一點必須說明
ID|FNAME |LNAME | STATE | CITY
2 |xxxxx3 |xxxxx3| toronto | yy3 <- doctor
3 |yyyyy3 | | toronto | yy3 <- organization
4 |zzzzz3 |zzzzz3| toronto | yy3
,但只顯示該
ID|FNAME |LNAME | STATE | CITY
2 |xxxxx3 |xxxxx3| toronto | yy3 <- doctor
4 |zzzzz3 |zzzzz3| toronto | yy3 <- doctor
你可以做的,而不是一個交叉聯接UNION操作。 – markg