开发者

Joins in SQL for retriving data from two tables

There ar开发者_如何学JAVAe two tables A and B. You are retreiving data from both tables where all rows from B table and only matching rows from A table should be displayed. Which of the following types of joins will you apply between A and B tables?

- Inner join
- Left outer join
- Right outer join
- Self join


Use left outer hoin or right outer join.

For example, the following satisfy your requirement.

select * from tableB
Left outer join tableA
on tableB.ID= tableA.ID

Or

select * from tableA
Right outer join tableB
on tableA.ID= tableB.ID

Better way to understand:

Joins in SQL for retriving data from two tables


Easy, I would go with (B).

SELECT * FROM B x
LEFT JOIN A y
  on x.someColName = y.someColname

EDIT: can also use Right join

SELECT * FROM A x
RIGHT OUTER JOIN B y
  on x.someColName = y.someColname


This looks like homework, but it's dead simple enough that I'll just say that you're asking for B LEFT JOIN A.


Join Left

http://www.w3schools.com/Sql/sql_join_left.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜