====================================
On 2005-07-25 at 10:15:14 [+0200], David Fowler
<[EMAIL PROTECTED]> wrote:
> SELECT * FROM table1, table2
> WHERE (table1.value LIKE "%value%" AND table1.table2_id = table2.id);
> This query works perfectly, can't fault it.
> But when I do this, SQLite locks out (Command line interface, and PHP5)
> Query 2:
> SELECT * FROM table1, table2
> WHERE ((table1.value LIKE "%value%" AND table1.table2_id = table2.id);
> OR (table1.value LIKE "%different_value%" AND table1.table2_id =
> table2.id));

I think this is a good example of why I use explicit JOINS.

SELECT * FROM table1
INNER JOIN table2 ON
(table2.id = table1.table2_id)
WHERE
table1.value LIKE '%value%' OR table1.value LIKE '%value%')

Doesn't this do what you want?
--
Charlie Clark
Communications Manager
yellowTAB GmbH
Tel: +49-211-600-3657
http://www.yellowtab.com
mailto: [EMAIL PROTECTED]

====================================
Thanks Charlie, thats exactly how I should be doing it. I would imagine there are some performance benefits from doing it this way too. Now I've just got to make it work for my select that involves six not two tables! Looks like I'll be getting my thick SQL book out for a while. Though my new code did look rather promising, I think this way will probably be better for my multiple tables.
New Code:
SELECT * FROM table1, table2
WHERE (table1.value LIKE "%value1%" AND table1.table2_id = table2.id) GROUP BY table2.id
UNION
SELECT * FROM table1, table2
WHERE (table1.value LIKE "%value2%" AND table1.table2_id = table2.id) GROUP BY table2.id;

Now I can fix this problem and move on. Thanks again.
Dave.


Reply via email to