Jump to content

Archived

This topic is now archived and is closed to further replies.

slkhlaw

SELECT question

Recommended Posts

I have the following table

 

Table User

UID

FirstName

LastName

 

Table Email

UID

Email-ID

EmailAddress

 

Table Telephone

UID

Telephone ID

Telephone

 

Table Fax

UID

Fax-ID

Fax

 

I would like do two things

 

1) Output all UID, FirstName, LastName, EmailAddress, Telephone, Fax in one output. How do I do that?

2) Output UID, FirstName, LastName, EmailAddress, Telephone, Fax with given UID in one output. How do I do that?

 

(One user may have multiple Telephone, Email address and Fax)

 

I would appreciate if anyone could lend me a hand in this. Thank you very much indeed.

Share this post


Link to post
Share on other sites

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] UID,Firstname,Lastname,EmailAddress,Telephone,Fax

FROM User u

LEFT JOIN Email e ON u.UID=e.UID

LEFT JOIN Telephone t ON u.UID=t.UID

LEFT JOIN Fax f ON u.UID=f.UID [!--sql2--][/div][!--sql3--]

 

For the second one, add a WHERE clause

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] UID,Firstname,Lastname,EmailAddress,Telephone,Fax

FROM User u

LEFT JOIN Email e ON u.UID=e.UID

LEFT JOIN Telephone t ON u.UID=t.UID

LEFT JOIN Fax f ON u.UID=f.UID

WHERE u.UID=1 [!--sql2--][/div][!--sql3--]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.