Mysql 这个条款在哪里模棱两可
使用dallasfoodMysql 这个条款在哪里模棱两可,mysql,sql,Mysql,Sql,使用dallasfood select estab_id from estab as EST left join inspect as INSP on EST.estab_id = INSP.estab_id where inspdate = '8-3-17' and estab_id = '2473' 试图找到如何修复estab_id的子句不明确结果。我试图找到某个日期的特定机构上返回的冲突,但无法找出其不明确的原因在选择中使用表alis名称,因为这两个表
select estab_id
from estab as EST
left join inspect as INSP
on EST.estab_id = INSP.estab_id
where inspdate = '8-3-17'
and estab_id = '2473'
试图找到如何修复estab_id的子句不明确结果。我试图找到某个日期的特定机构上返回的冲突,但无法找出其不明确的原因在选择中使用表alis名称,因为这两个表中都有
estab_id
列,这就是为什么它在查询中显示不明确的原因
select EST.estab_id
from estab as EST
left join inspect as INSP
on EST.estab_id = INSP.estab_id
where inspdate = '8-3-17'
and EST.estab_id = '2473'
您应该限定查询中的所有列,特别是当有多个表时
最好的别名通常是最短的——表名的缩写。此外,您应该使用标准的日期格式,假设您的日期存储为日期
比如说:
select e.estab_id
from estab e left join
inspect i
on e.estab_id = i.estab_id and i.inspdate = '2017-08-03'
where e.estab_id = 2473;
其他一些注意事项:
- 我删除了
周围的单引号。如果2473
确实是一个字符串,则包含单引号。如果它是一个数字,那么这是一个坏主意,因为您正在混合数据类型estab_id
- 我假设
来自insupdate
,因此它符合inspect
I
中第二个表上的条件通常位于left join
子句中。否则,联接将变为内部联接on
提供一个标识符