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
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,
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 ('$
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
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
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
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
[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
[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;
+--+--
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
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
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
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
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
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
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
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,
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
18 matches
Mail list logo