我创建了这个搜索sql。但我只想搜索那些血型为a +的人,而不是khilgoan师dhaka和地区dhaka。但我的搜索结果没有显示
Select d.user_id,
d.firstname,
d.`blood_group`,
a.`city_thana`,
a.`division`,
a.`district`
From donar d
natural join addrsess a
where `blood_group` = 'A+'
and a.`city_thana` = 'Khilgoan'
and a.`division` = 'Dhaka'
and a.`district` = 'Dhaka'
答案 0 :(得分:0)
由于无法查看表格的投放,natural join
可能会弄乱查询,因为所有具有相同名称的列都将加入
答案 1 :(得分:0)
只有当您确定两个表都具有相同名称的公共字段时,才能或应该执行Natural Join
,否则请明确执行INNER JOIN
。尝试使用显式连接修改您的查询,例如
Select d.user_id,
d.firstname,
d.`blood_group`,
a.`city_thana`,
a.`division`,
a.`district`
From donar d
INNER JOIN addrsess a ON d.user_id = a.user_id (may be other column)
where d.`blood_group` = 'A+'
and a.`city_thana` = 'Khilgoan'
and 'Dhaka' IN (a.`division`,a.`district`)
答案 2 :(得分:0)
此代码解决了问题......
select d.user_id,d.firstname,d.`blood_group`,a.`city_thana`,a.`division`,a.`district` from donar d natural join address a
where `blood_group` like 'Bo' and `city_thana`='Bangsal' like `division`='DHAKA' and `district`='DHAKA'