mysql嵌套查询
SELECT*FROMpersonal_informationWHEREssxy=("SELECTdict_value0FROMsys_dictWHEREdict_typ...
SELECT * FROM personal_information WHERE ssxy =("SELECT dict_value0 FROM sys_dict WHERE dict_type='xy' AND dict_key=1")
SELECT * FROM personal_information WHERE ssxy ="SELECT dict_value0 FROM sys_dict WHERE dict_type='xy' AND dict_key=1"
这个mysql语句为什么查不出来数据不报错,用in也不对
正确的:
SELECT * FROM personal_information dd
LEFT JOIN sys_dict dic ON dic.dict_type = 'xy' AND dic.dict_key = dd.ssxy 展开
SELECT * FROM personal_information WHERE ssxy ="SELECT dict_value0 FROM sys_dict WHERE dict_type='xy' AND dict_key=1"
这个mysql语句为什么查不出来数据不报错,用in也不对
正确的:
SELECT * FROM personal_information dd
LEFT JOIN sys_dict dic ON dic.dict_type = 'xy' AND dic.dict_key = dd.ssxy 展开
展开全部
select PI.* from personal_information PI inner join sys_dict SD on PI.ssxy=SD.dict_value0 and SD.dict_type='xy' and SD.dict_key=1
select * from personal_information where ssxy in(select dict_value0 as ssxy from sys_dict where dict_type='xy' and dict_key=1)
试试吧 感觉第一种比第二种把握大一些
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |