select a.c1, b.c2 from a left join b on a.c1 = b.c1
其實left join 是指 把 b 沒有符合 的也列出來 但是加了 where 會強制 b.c2 一定要符合 2009-10-23
範例
//195筆
select `store_book`.* from `store_book` where `store_book`.`store_code`='P018' and `store_book`.`seat_name`='不限定'
//34筆 - cross table 相同user_id
select `store_book`.*,`user`.`UName`,`user`.`UPhone` from `store_book`, `user` where `user`.user_id=`store_book`.user_id and `store_book`.`store_code`='P018' and `store_book`.`seat_name`='不限定'
用left join從user表中來擴充UName,UPhone資訊
// 195筆
select `store_book`.*,`user`.`UName`,`user`.`UPhone` from `store_book` left join `user` on `user`.user_id=`store_book`.user_id where `store_book`.`store_code`='P018' and `store_book`.`seat_name`='不限定'
沒有留言:
張貼留言