homepage Welcome to WebmasterWorld Guest from 184.72.82.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Multiple ON conditions
Querying multiple tables with multiple on conditions
neo_brown




msg:3524637
 12:45 am on Dec 11, 2007 (gmt 0)

I have a query which joins several tables, the query works fine until I try to incorporate pagination into the mix. To do so I need to add another on condition but I cannot seem to make it work.
(edit MYSQL/PHP)

The original query which works just fine is this:

FROM (table1
LEFT JOIN table2
ON table1.id = table2.id)

LEFT JOIN table3
ON table1.id = table3.id

LEFT JOIN table4
ON table1.id = table4.id

LEFT JOIN table5
ON table1.id = table5.id ORDER BY table1.id DESC LIMIT 10;";

Then I try to add another condition at the end.

FROM (table1
LEFT JOIN table2
ON table1.id = table2.id)

LEFT JOIN table3
ON table1.id = table3.id

LEFT JOIN table4
ON table1.id = table4.id

LEFT JOIN table5
ON table1.id = table5.id < '$lid' ORDER BY table1.id DESC LIMIT 10;";

It fails! It still gets results, it just does not limit them.

Any one have any ideas? Is what I am trying to do even possible using this method?
Any help greatly appreciated.

 

LifeinAsia




msg:3524642
 12:54 am on Dec 11, 2007 (gmt 0)

table1.id = table5.id < '$lid'

I don't know if this was a typo, but it's not valid SQL.

Did you mean "table1.id = table5.id AND table5.id < '$lid'" instead?

neo_brown




msg:3524645
 1:00 am on Dec 11, 2007 (gmt 0)

Not a typo, that is me getting experimental (I thought I had seen queries structured like that?)
The method you mention is the way I tried at first but it also did not work.

Thanks for the feed back!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved