Re: mysql UNION

2005-06-06 Thread mfatene
Hi, If we forget the first method which i mis-adviced, i can give a third which is generic. suppose that you have an indexed "type" column on each table (what i did). You can work with 3 variables. If they are different, you query for a join, if they are equal, you transform the join to a simple q

Re: mysql UNION

2005-06-06 Thread mfatene
did'n arrive. re-submitted -- sorry Selon [EMAIL PROTECTED]: > Hi, > If we forget the first method which i mis-adviced, i can give a third which > is > generic. > > suppose that you have an indexed "type" column on each table (what i did). > You > can work with 3 variables. If they are different,

Re: mysql UNION

2005-06-05 Thread Michael Stassen
Sebastian wrote: Ah.. OK. I'll give that a shot instead.. Also, now that i am doing some thinking on optimizing... should the $cat clause be present first in the where clause? since it decides if it should get results or not. for example: WHERE MATCH(...) AGAINST(... IN BOOLEAN MODE) AND ('$

Re: mysql UNION

2005-06-05 Thread Sebastian
Michael Stassen wrote: Sebastian wrote: Michael Stassen wrote: Now, I never said this couldn't be done in SQL. Assuming $cat is already set, the statement in $sql below should do what you asked for: $sql = "SELECT id, 'news' AS type, FROM news WHERE ($cat = '' OR $cat

Re: mysql UNION

2005-06-05 Thread Michael Stassen
Sebastian wrote: Michael Stassen wrote: Now, I never said this couldn't be done in SQL. Assuming $cat is already set, the statement in $sql below should do what you asked for: $sql = "SELECT id, 'news' AS type, FROM news WHERE ($cat = '' OR $cat = 'news') UNION

Re: mysql UNION

2005-06-05 Thread Michael Stassen
Sebastian wrote: Michael Stassen wrote: So, why spend days trying to come up with complicated, ugly sql when it can be done in 5 minutes with simple, easy-to-read php? Michael i only posted snip of the query.. it is much larger and complex than just a SELECT. i am going MATCH, AGAINST, LE

Re: mysql UNION

2005-06-05 Thread Sebastian
Michael Stassen wrote: [EMAIL PROTECTED] wrote: Hi Sebastian; There is always crazy things somewhere. I'll give you two methods for that : mysql> select id,'news' as selected, type from news -> union select id,'faq' as selected, type from faq -> union select id,'forum' as selected, ty

Re: mysql UNION

2005-06-05 Thread Michael Stassen
[EMAIL PROTECTED] wrote: I agree with you, just see that if .. sql = "SELECT id, '$cat' AS type, ... FROM $cat"; is exactly what is done in prepare statement. Yes, I acknowledged that in my next message (a reply to yours). dynamic sql is better than application level statement preparation, w

Re: mysql UNION

2005-06-05 Thread Michael Stassen
[EMAIL PROTECTED] wrote: Hi Sebastian; There is always crazy things somewhere. I'll give you two methods for that : mysql> select id,'news' as selected, type from news -> union select id,'faq' as selected, type from faq -> union select id,'forum' as selected, type from forum; +--+--

Re: mysql UNION

2005-06-05 Thread Sebastian
Michael Stassen wrote: Sebastian wrote: Michael Stassen wrote: Sebastian wrote: i have a query with 3 union selects: SELECT id, 'news' AS type, FROM news UNION SELECT id, 'faq' AS type, FROM faq UNION SELECT id, 'forum' AS type, FROM forum which wor

Re: mysql UNION

2005-06-05 Thread mfatene
I agree with you, just see that if .. sql = "SELECT id, '$cat' AS type, ... FROM $cat"; is exactly what is done in prepare statement. dynamic sql is better than application level statement preparation, when you use stored procedure. but since this is the a habit in mysql, i'll keep this for oracle

Re: mysql UNION

2005-06-05 Thread Michael Stassen
Sebastian wrote: Michael Stassen wrote: Sebastian wrote: i have a query with 3 union selects: SELECT id, 'news' AS type, FROM news UNION SELECT id, 'faq' AS type, FROM faq UNION SELECT id, 'forum' AS type, FROM forum which works just fine and selects

Re: mysql UNION

2005-06-05 Thread mfatene
The second method is dynamic sql with prepare statement from string. It's better for the reason that the query is generated to retrieve data from just one table (not an union which implies 3 tables). The day your tables will be huge, i'm sure you will use the second method. two crazy people can

Re: mysql UNION

2005-06-04 Thread Sebastian
Hi, your second method is probably a little too confusing (advanced) for me to understand. I used your first method which works fine.. thanks for the crazy stuff, somtimes you need two crazy people to come up with a solution ;) [EMAIL PROTECTED] wrote: Hi Sebastian; There is always crazy thin

Re: mysql UNION

2005-06-04 Thread mfatene
Hi Sebastian; There is always crazy things somewhere. I'll give you two methods for that : mysql> select id,'news' as selected, type from news -> union select id,'faq' as selected, type from faq -> union select id,'forum' as selected, type from forum; +--+--+---+ | id | s

Re: mysql UNION

2005-06-04 Thread Sebastian
Michael Stassen wrote: Sebastian wrote: i have a query with 3 union selects: SELECT id, 'news' AS type, FROM news UNION SELECT id, 'faq' AS type, FROM faq UNION SELECT id, 'forum' AS type, FROM forum which works just fine and selects everything from all

Re: mysql UNION

2005-06-04 Thread leegold
Couldn't you just test "page.php?cat=faq" with an if-then-else? Depending on what is the GET variable you then can change the SQL, easy w/PHP. On Sat, 04 Jun 2005 14:15:40 -0400, "Sebastian" <[EMAIL PROTECTED]> said: > i have a query with 3 union selects: > > SELECT id, 'news' AS type,

Re: mysql UNION

2005-06-04 Thread Michael Stassen
Sebastian wrote: i have a query with 3 union selects: SELECT id, 'news' AS type, FROM news UNION SELECT id, 'faq' AS type, FROM faq UNION SELECT id, 'forum' AS type, FROM forum which works just fine and selects everything from all 3 tables.. but say i wa

mysql UNION

2005-06-04 Thread Sebastian
i have a query with 3 union selects: SELECT id, 'news' AS type, FROM news UNION SELECT id, 'faq' AS type, FROM faq UNION SELECT id, 'forum' AS type, FROM forum which works just fine and selects everything from all 3 tables.. but say i want to make a cond