【发布时间】:2013-02-04 19:35:27
【问题描述】:
我希望 parent 在此查询中是唯一的:
select
*,
(select state_name
from tbl_states
where state_id = tbl_cities.parent_id) as parent
from
tbl_cities
ORDER BY
parent
我尝试过使用:
select
*,
DISTINCT (select state_name
from tbl_states
where state_id = tbl_cities.parent_id) as parent
from
tbl_cities
ORDER BY
parent
但它给出了一个错误。
【问题讨论】:
-
抛出了什么错误?
-
#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在“DISTINCT”附近使用正确的语法(在第 1 行从 tbl_states where state_id = tbl_cities.parent_i 中选择 state_name