[英]Mysql query based on row value of another table
Have two mysql tables such as 有两个mysql表,例如
Table1 表格1
Id
Field1
Field2
Table2 表2
Id
LinkId
Field3
Field4
The common fields to link the tables are Table1.Id
and Table2.LinkId.
链接表的公共字段是
Table1.Id
和Table2.LinkId.
Also important tha Table2 can have multiple rows where LinkId are the same. 同样重要的是,Table2可以具有多个行,其中LinkId相同。
So what I have been trying to figure is a mysql query to Select all rows in Table1 that have a linked row or more in Table2 where Field3 contains a certain value. 因此,我一直试图找出一个MySQL查询来选择Table1中的所有行,其中Table2中具有链接的行或更多行,其中Field3包含某个值。 Is this easily possible?
这容易吗?
Simply use JOIN
只需使用
JOIN
SELECT Table1.*
FROM Table1 A JOIN Table2 B ON A.Id = B.LinkID
WHERE B.Field3 IN ('Your inputs')
You can have multiple tables in the FROM
clause: 在
FROM
子句中可以有多个表:
SELECT *
FROM Table1, Table2
WHERE Table2.Field3 = 'certain value'
AND Table1.Id = Table2.LinkId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.