Dadu Da

Dadu Da

  • NA
  • 43
  • 35.5k

How to use join query to fetch data from more than two table

Aug 24 2012 2:06 AM

How to use join query to fetch data from more than two table

Hi friends,

Once I need your help,

I have three table in my database.

1> wedding

 

Field Name

Data Type

wedID

Int (Primary Key)

wedName

Varchar(50)

2> siteSelect

 

Field Name

Data Type

wedID

int

siteID

Int

siteStatus

Varchar(50)

3>webSite

 

Field Name

Data Type

siteID

Int

siteName

Varchar(50)

siteFile

Varchar(MAX)


"ws" is alias of "webSite" table , "s" is Alias of "siteSelect" Table

all data from "webSite" table and only data from "siteSelect" where s.siteStatus do not display "Yes" if wedID not match

I  want out  put as followed

ws.siteID             ws.siteName          ws.siteFile              s.wedID         s.sitestatus

1                    Show              show.jpeg        6               Yes

2                    My View         my view.png    5                     

3                    Dream            dream.jpeg       3

I try following sql query

select DISTINCT(ws.siteID),s.wedID,ws.siteName,ws.siteFile,s.siteStatus from wedding wd, webSite ws left outer join  siteSelect s on ws.siteID=s.siteID where wd.wedID=@wedID

but Output as follwed

I  want out  put as followed

ws.siteID             ws.siteName          ws.siteFile               s.wedID          s.sitestatus

1                    Show              show.jpeg         6                Yes

2                    My View         my view.png     5                Yes   

3                    Dream            dream.jpeg       3                Yes

           


Answers (1)