MYSQL两个表关联查询_MySQL
时间:2021-07-01 10:21:17
帮助过:19人阅读
SELECT
states.state_id,
states.state_name,
cities.city_id,
cities.city_name,
cities.region_id
FROM states
INNER JOIN cities
ON states.state_id=cities.state_id
WHERE states.countrycode=”counttrycode“;
也可以使用别名:
如下:
SELECT
s.state_id,
s.state_name,
c.city_id,
c.city_name,
c.region_id
FROM states s
INNER JOIN cities c
ON s.state_id=c.state_id
WHERE s.countrycode=”counttrycode“;
s 是states的别名, c是cities的别名。这样当名字很长时比较好用。