Jump to content

SELECT question


slkhlaw

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.

Link to comment
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--]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.