使用子查询进行选择

时间:2016-02-04 22:08:14

标签: mysql sql

考虑以下表格架构:// Sets the image for the EU volume limit. When appropriate, this image will be displayed on top of the // maximumVolumeSliderImage. It must be visually distinct from the maximumVolumeSliderImage, and use // a color similar to the default, to convey a sense of warning to the user. The same image is used for // all control states. For debugging purposes, switch on the "EU Volume Limit" setting in the Developer // menu of the Settings application to always enable the volume limit. @property (nonatomic, strong, nullable) UIImage *volumeWarningSliderImage NS_AVAILABLE_IOS(7_0); 。假设这些公司可能位于几个城市。找到所有公司 位于'公司X'所在的每个城市。

这是正确的SQL代码:

 company(company-name, city 

这是否与:

相同
 select company name from company
 where city in (select city from company where company-name = 'Company X')

2 个答案:

答案 0 :(得分:0)

使用联接

可能更好
SELECT DISTINCT c1.company_name
FROM company AS c1
JOIN company AS c2 ON c1.city = c2.city
WHERE c2.company_name = 'Company X'

答案 1 :(得分:-1)

如果您的字段被调用"公司名称"查询应该是

select "company-name" 
from company 
where city in (select city from company where "company-name" = 'Company X')

如果该公司的名称知道它的独特之处,您可以替换" in"运算符" ="