如何根据 mysql 中的另一个 table 从 table select
How to select from a table based on another table in mysql
我有 2 table
Table一个
id ifClosed
1 1
2 0
3 0
Table B
id remittance
1 50.00
1 10.00
2 5.25
3 8.20
3 1.60
我需要做
select 来自 table b 的所有记录,其中 ifClosed 列被标记为“0”
id remittance
2 5.25
3 8.20
3 1.60
我的试用期:
select * from table B where tableA.ifclosed = '0'
使用 JOIN 子句
SELECT tableB.*
FROM tableB JOIN tableA ON tableB.id=tableA.id
WHERE tableA.ifClosed = 0
这是一个基本的 JOIN。查看 JOINS
上的一些指南
select *
from TableB
inner join TableA
on TableA.id = TableB.id
where TableA.ifClosed = 0
检查这个:
select * from TableB b
where b.Id in (select a.Id from TableA a where a.IfClosed = '0')
使用 left out join 以便仅显示 table b 中存在的 ID。希望这有帮助
SELECT tableB.*
从 tableB 左外连接 tableA ON tableB.id=tableA.id
其中 tableA.ifClosed = 0
select
*
from
TableB
join TableA on TableA.id = TableB.id and TableA.IfClosed = 0
不需要 where 子句
试试这个查询:
select * from tableB, tableA
where tableA.ifclosed = '0'
and tableA.id = tableB.id
我有 2 table
Table一个
id ifClosed
1 1
2 0
3 0
Table B
id remittance
1 50.00
1 10.00
2 5.25
3 8.20
3 1.60
我需要做 select 来自 table b 的所有记录,其中 ifClosed 列被标记为“0”
id remittance
2 5.25
3 8.20
3 1.60
我的试用期:
select * from table B where tableA.ifclosed = '0'
使用 JOIN 子句
SELECT tableB.*
FROM tableB JOIN tableA ON tableB.id=tableA.id
WHERE tableA.ifClosed = 0
这是一个基本的 JOIN。查看 JOINS
上的一些指南select *
from TableB
inner join TableA
on TableA.id = TableB.id
where TableA.ifClosed = 0
检查这个:
select * from TableB b
where b.Id in (select a.Id from TableA a where a.IfClosed = '0')
使用 left out join 以便仅显示 table b 中存在的 ID。希望这有帮助
SELECT tableB.* 从 tableB 左外连接 tableA ON tableB.id=tableA.id 其中 tableA.ifClosed = 0
select
*
from
TableB
join TableA on TableA.id = TableB.id and TableA.IfClosed = 0
不需要 where 子句
试试这个查询:
select * from tableB, tableA
where tableA.ifclosed = '0'
and tableA.id = tableB.id