从两个表中提取SQL数据 [英] Pull SQL data from two tables
问题描述
我有一个名为db.data
和db.info
的表. db.data
表的每个条目都有一个name
和dateadded
列. info
表的每个名称都有一个name
和status
列(状态为 y 或 n ). 我想按日期从db.data表中获取添加到该数据库的所有名称的数据,但前提是状态(db.status中的一个)为n.
I have a table called db.data
and db.info
. The db.data
table has a name
and dateadded
column for every entry. The info
table has a name
and a status
column for every name (status is either y or n). I would like to pull the data from the db.data table for all the names added to that db by date but only if the status (the one in db.status) is n.
我一直在寻找并找到JOIN
,但这似乎仅在两个表中的数据相同时才起作用.在这里,名称是相同的,但是我希望从db.data中提取数据,但仅将名称"单元格(在两个表中)的状态设置为"n".
I have been looking around and found JOIN
, but that seems to only work if the data is the same in both tables. Here, the names are the same, but I want the data extracted from db.data but only in the status for the 'name' cell (which is in both tables) is set to 'n'.
推荐答案
我认为这是您想要的:
select d.name, d.dateadded
FROM db.info i, db.data d
WHERE i.name = d.name
AND i.status = 'n';
这篇关于从两个表中提取SQL数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!