Mysql?е???????,????????????
???????????? ???????[ 2015/3/17 14:19:12 ] ????????MySQL ????? ???????
??????????: ???????????
????????????: ?????????????У?????????????????????????????У?????????????????????
????????????: ?????????????У?????????????????????????????У?????????????????????
???????????: ???????????????????У?????????????????????????????????С?
????????????: ????????????????????κ????????????????????????????????е????????????????????????ж??????
???????????ɡ?
??A
id name
1 ??
2 ??
3 ??
??B
id address A_id
1 ???? 1
2 ??? 3
3 ??? 10
/******************************** left join ??????*****************************************/
??????:A?????B?????????????????.(left join ?? left outer join )
SQL??????£?
SELECT A.name?? B.address
FROM A
LEFT JOIN B ON A.id = B.A_id
?????????
name address
?? ????
?? NULL
?? ???
/******************************** right join ??????*****************************************/
??????:B?????A?????????????????.(right join ?? right outer join )
SQL??????£?
SELECT A.name?? B.address
FROM A
RIGHT JOIN B ON A.id = B.A_id
?????????
name address
?? ????
?? ???
NULL ???
/******************************** inner join ??????*****************************************/
??????:A??B??????????1??????????????С?????????
SQL??????£?
select A.name??B.address from A
inner join B
on A.id = B.A_id
?????????
name address
?? ????
?? ???
inner join ???????????????sql:
SELECT A.name?? B.address
FROM A?? B
WHERE A.id = B.A_id
/******************************** full join ?????*****************************************/
???:???????????????????????????????е?????????????????????????????????С????????????????
?????????????????????????????????????????????????????е?????????????????????????????????
??(full join ?? full outer join )
SQL??????£?
select * from A
full join B
?????????
id name id address A_id
1 ?? 1 ???? 1
2 ?? 1 ???? 1
3 ?? 1 ???? 1
1 ?? 2 ??? 3
2 ?? 2 ??? 3
3 ?? 2 ??? 3
1 ?? 3 ??? 10
2 ?? 3 ??? 10
3 ?? 3 ??? 10
/******************************** CROSS JOIN(????????where...)***********************************/
????????3*3=9????????????????
SQL??????£?
SELECT * FROM A
CROSS JOIN B
?????????
id name id address A_id
1 ?? 1 ???? 1
2 ?? 1 ???? 1
3 ?? 1 ???? 1
1 ?? 2 ??? 3
2 ?? 2 ??? 3
3 ?? 2 ??? 3
1 ?? 3 ??? 10
2 ?? 3 ??? 10
3 ?? 3 ??? 10
CROSS JOIN?????:
select * from A??B
???????:
????1. on A.id = B.id ????? using(id)//?????????????
????2. ?? MySQL ?????????м???????????????????????????????????
??????? EXPLAIN ??? MySQL ??????????????б??д???????????????????????????
?????????? USE INDEX (key_list)?????????? MySQL ????????????к???????????????в??????С?
?????????????? IGNORE INDEX (key_list) ?????????? MySQL ????????????????
????Ч??????:
????1.inner join??left join??
?????:inner join ???????????????sql: SELECT A.name?? B.address FROM A?? B WHERE A.id = B.A_id
???????????????????????????.
????2.??????ν?????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11