Welcome to WebmasterWorld Guest from 54.159.190.106

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)

10+ Year Member



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)

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



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)

10+ Year Member



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!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month