Jump to content


Photo

SELECT question


  • Please log in to reply
1 reply to this topic

#1 slkhlaw

slkhlaw
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 23 November 2005 - 12:03 PM

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.

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 23 November 2005 - 06:14 PM

[!--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--]
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users