mysql左加入 MySQL左加入子查詢

2021-10-17 21:58:10 字數 701 閱讀 5487

我在join語句中使用子查詢組合了乙個相當簡單的查詢.它僅在我在子查詢select中包含*時才有效.為什麼?

這很有效

$sql = 'select locations.id, title, name, hours.lobby

from locations

left join states on states.id = locations.state_id

left join (select *, type_id is not null as lobby from location_hours) as hours on locations.id = hours.location_id

group by locations.id';

這沒有$sql = 'select locations.id, title, name, hours.lobby

from locations

left join states on states.id = locations.state_id

left join (select type_id is not null as lobby from location_hours) as hours on locations.id = hours.location_id

group by locations.id';

我應該這樣做嗎?如果你不需要所有的領域,我認為*不是最好的?

mysql 左連線 重複 mysql左連線重複行

我正在設計乙個類似於4個 的字典資料庫 words wordid lemma senses wordid synsetid synsets synsetid definition samples synsetid sample所以我使用下面的查詢來獲取所有意義定義和樣本 if isset searc...

MySQL左連線 右連線

表a記錄如下 aid anum 1 a20050111 2 a20050112 3 a20050113 4 a20050114 5 a20050115 表b記錄如下 bid bname 1 2006032401 2 2006032402 3 2006032403 4 2006032404 8 200...

mysql左連線去重

create table tb batch id int 11 not null auto increment,batch no varchar 32 comment 批次號 contract id int 11 comment 合同id contract no varchar 64 comment...