1. Internal connection
i. No connection
select * from t_book, t_bookType;

ii. Where =
select bookName, author, bookTypeName from t_book, t_bookType where t_book.bookTypeId = t_bookType.id;

iii. Abbreviation
select tb.bookName, tb.author, tbt.bookTypeName from t_book tb, t_bookType tbt where tb.bookTypeId = tbt.id;

2. External connection
Be careful: left join --> all information of first table
right join --> all information of second table
select * from t_book tb left join t_bookType tbt on tb.bookTypeId = tbt.id;
select * from t_book tb right join t_bookType tbt on tb.bookTypeId = tbt.id;

3. Multi condition --> and
select tb.bookName, tb.author, tb.price, tbt.bookTypeName from t_book tb, t_bookType tbt where tb.bookTypeId = tbt.id and tb.price>70;

本文详细介绍了SQL中的连接查询,包括内部连接、外部连接以及多条件连接等不同类型的使用方法,并通过具体的例子展示了如何进行表之间的连接操作。
987

被折叠的 条评论
为什么被折叠?



