Home > Database > Mysql Tutorial > MYSQL 两个表关联查询_MySQL

MYSQL 两个表关联查询_MySQL

WBOY
Release: 2016-06-01 13:06:35
Original
1348 people have browsed it
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的别名。这样当名字很长时比较好用。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template