从两个表中提取SQL数据 [英] Pull SQL data from two tables

查看:263
本文介绍了从两个表中提取SQL数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为db.datadb.info的表. db.data表的每个条目都有一个namedateadded列. info表的每个名称都有一个namestatus列(状态为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆