在此solution上,用户正在查询id以显示select中的其他列,但查询仅在单个列上不同。我试过这样做,但无法正确使用语法。这是查询,但我只想在DevelopmentDisplay
列上进行区分。
SELECT DISTINCT
`RESI`.`DevelopmentDisplay`,
`RESI`.`City`,
`RESI`.`ZipCode`
FROM
`RESI`
WHERE
`RESI`.`ZipCode` = '91263'
ORDER BY
`RESI`.`DevelopmentDisplay` ASC
答案 0 :(得分:1)
是的,您可以自行加入表格。
我看到两个这样的选项。但是,我建议您索引DevelopmentDisplay列。根据记录的数量,它可能变得非常慢。
SELECT
t1.DevelopmentDisplay,
t1.City,
t1.ZipCode
FROM
RESI t1,
(SELECT DISTINCT DevelopmentDisplay FROM RESI) t2
WHERE
t1.ZipCode = '91263' AND
t1.DevelopmentDisplay = t2.DevelopmentDisplay;
可替换地:
SELECT
t1.DevelopmentDisplay,
t1.City,
t1.ZipCode
FROM
RESI t1,
WHERE
t1.ZipCode = '91263' AND
t1.DevelopmentDisplay IN (SELECT DISTINCT DevelopmentDisplay FROM RESI);