Welcome to WebmasterWorld Guest from 54.224.164.166

Forum Moderators: open

Message Too Old, No Replies

Multiple ON conditions

Querying multiple tables with multiple on conditions

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

Junior Member

10+ Year Member

joined:Oct 2, 2003
posts:129
votes: 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.

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

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5710
votes: 89


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?

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

Junior Member

10+ Year Member

joined:Oct 2, 2003
posts:129
votes: 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!

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members