By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,040 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,040 IT Pros & Developers. It's quick & easy.

retrive results from 4 tables

100+
P: 201
Hello -

I'm trying to create a dynamic results table layout from 4 tables.

I want to have the data from the 2 tables asstatusupdate and asstatusdata even if the other two tables do not have a matching record.

I'm coding the site in php.

Thanks in advance for your help!

here is the query:

Expand|Select|Wrap|Line Numbers
  1. SELECT a.Id, a.Type, 
  2. a.Dates, 
  3. a.UIdFk, 
  4. b.Id as Did, 
  5. b.comment, 
  6. b.dates as Day, 
  7. b.sfk as Sfk ,
  8. c.sfk as sfk1, 
  9. d.Memo as Memo
  10. FROM 
  11. asstatusupdate as a,  
  12. asstatusdata as b , 
  13. asmanystatusupdate as c,
  14. ascomments as d
  15. where a.Id=b.sfk and a.uidfk='1' and b.sfk=c.sfk and c.cfk=d.id
  16.  
Apr 19 '11 #1
Share this Question
Share on Google+
1 Reply


code green
Expert 100+
P: 1,726
You need to use LEFT JOIN instead of cartesian join
Expand|Select|Wrap|Line Numbers
  1. FROM  
  2. asstatusupdate as a   
  3. LEFT JOIN asstatusdata as b ON a.Id=b.sfk
  4. LEFT JOIN asmanystatusupdate as c ON b.sfk=c.sfk 
  5. LEFT JOIN ascomments as d ON c.cfk=d.id 
  6. WHERE a.uidfk='1' 
  7.  
Apr 20 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.