1, the connection: the coupling field is present in both tables relationship records that meet the conditions for forming the connection record set
Select A.name,B.name from A inner join B on A.id=B.id和
Select A.name, B.name from A, B where A.id = B.id result is the same (within the inner connector keyword can be omitted);
2, the external connection: the connection is divided into left and right outer external connection
Left connecting A, B results in Table A include all records recording and B is qualified.
A right-linking, results and left the table B coupling B, A result is the same, that is to say:
Select A.name,B.name from A Left Join B on A.id=B.id和
Select A.name, B.name from B Right Join A on B.id-A.id result of execution is the same.
3, all links
4, no link
5, three tables join query
select username,psw,gname,tel from (t1 left join t2 on t1.t1_id=t2.t1_id) left join t3 on t1.t1_id=t3.t1_id
6, the ultimate three-table join query
items: product table, item_visit_stats: merchandise to access the table, item_trade_stats: merchandising table
SELECT i.num_iid, i.title, i.price, SUM(iv.user_visits) AS uv,it.buyer_num,it.item_num,it.item_num*i.price AS turnover
FROM (items AS i RIGHT JOIN item_visit_stats AS iv ON i.num_iid=iv.num_iid)
LEFT JOIN (SELECT num_iid,SUM(buyer_num) AS buyer_num,SUM(item_num) AS item_num FROM item_trade_stats
WHERE seller_nick="XXXX" AND business_day BETWEEN '2010-08-14' AND '2010-08-15' GROUP BY num_iid)
AS it ON it.num_iid=iv.num_iid
WHERE i.nick="XXXX" AND iv.business_day BETWEEN '2010-08-14' AND '2010-08-15'
GROUP BY i.num_iid ORDER BY uv DESC