tags:

views:

80

answers:

5

There are 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
+1  A: 

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
VoodooChild
A: 

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

zebediah49
A: 

Join Left

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

Judas Imam
He was right, why he gets a downer?
VoodooChild
Who gets down and who gives?
Judas Imam
Possible reasons for down vote: 'Join Left' isn't one of the options, though 'Left outer join' is implied; 'Right outer join' is an equally valid answer.
onedaywhen
+4  A: 

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:

alt text

Pranay Rana
OMG I had this picture printed out not that long ago.... :)
VoodooChild
this one of the best article read and best way to understand about joins
Pranay Rana
A: 

The nice article to understand Joins

SQL Joins

Azhar