简体   繁体   English

SQL帮助,用于合并两个查询

[英]SQL Help for combining two queries

I want to combine these two SQL queries into one. 我想将这两个SQL查询合并为一个。 Any idea on how do I do it? 关于如何做的任何想法?

Select A, B, C 
from table1 
where condition1


select D 
from table2 
where table1.B=table2.E 

(table2 has the mapping of column B of table1) (表2具有表1的列B的映射)

I just want to fetch A,B,C,D in a single select query. 我只想在单个选择查询中获取A,B,C,D。 Any help would be appreciated. 任何帮助,将不胜感激。

INNER JOIN (read up on joins here http://www.w3schools.com/sql/sql_join.asp ) 内部联接(有关联接的详细信息, 请访问http://www.w3schools.com/sql/sql_join.asp

SELECT A, B, C, D
FROM table1 t1
INNER JOIN table2 t2 ON t1.B = t2.E
WHERE condition1

You could use a join : 您可以使用join

select A, B, C, D
from table1 
left join table2
on table1.B = table2.E 
where condition1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM