我有两个如下表。
表val1
e_id name val
1 A1 Abc
2 A2 Abd
3 A3 AbE
4 A4 AEd
5 A5 AEd
6 A6 Bdc
表val2
e_id e_desc t_id
1 desc1 1
2 desc1 1
1 desc1 2
3 desc1 1
5 desc1 1
2 desc1 2
4 desc1 2
5 desc1 2
2 desc1 3
4 desc1 1
6 desc1 1
3 desc1 2
6 desc1 2
3 desc1 2
5 desc1 3
我想仅通过表Val2上的e_id与e_id映射从表Val1中获取值,其中表Val2 t_id = 1
我正在使用此查询,但它正在获取所有数据。我该如何解决这个问题。这是我在下面显示的sql代码
SELECT
a.*,
b.e_desc
FROM
val1 AS a, val2 AS b
WHERE
b.e_id = a.e_id
AND EXISTS (SELECT
c.e_id
FROM val2 AS c
WHERE
c.e_id = a.e_id
AND c.t_id='1'
)
最佳答案
怎么样
SELECT a.*,
b.e_desc
FROM val1 AS a,
val2 AS b
WHERE b.e_id = a.e_id
AND b.t_id='1'
甚至
SELECT a.*,
b.e_desc
FROM val1 AS a INNER JOIN
val2 AS b ON b.e_id = a.e_id
WHERE b.t_id='1'
关于mysql - 存在关键字无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12274668/