If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query code problem.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-01-09, 21:20
ferdna ferdna is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
query code problem.

i have three tables table1, table2 and table3.

select * from table1, table2, table3
where table1.ID = "IDnumber"
table1.ID = table2.ID
table1.ID = table3.ID

if table3 doesnt have any rows with a matching IDnumber it wont return any results even if table1 and table2 have rows with the same IDnumber. how can i modify my query so i get a rows even if there are no rows on table3...
Reply With Quote
  #2 (permalink)  
Old 11-01-09, 21:24
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
I'd use a LEFT JOIN if I wwanted to do that.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 11-01-09, 21:25
ferdna ferdna is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
i'll research that... thank you... wow fast reply... =)
Reply With Quote
  #4 (permalink)  
Old 11-01-09, 21:27
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
We aim to please!

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #5 (permalink)  
Old 11-03-09, 11:13
Kenam Kenam is offline
Registered User
 
Join Date: Oct 2009
Posts: 2
select * from table2 JOIN table1 ON table1.ID = table2.ID JOIN table3 ON table1.ID= table3.ID


//This should join all three tables based on their IDs and you should be able to select anything from each table. Hope it helps
Reply With Quote
  #6 (permalink)  
Old 11-03-09, 11:37
ferdna ferdna is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
thank you guys. i got it working with the "LEFT JOIN" =)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On