Re: how to find biggest value of a field across 2 tables?
| From: | Hugh Bothwell | Date: | Fri, 06 Jul 2001 01:11:16 +0000 |
| Subject: | Re: how to find biggest value of a field across 2 tables? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-10102@lists.php.net to get a copy of this message | ||
"Noah Spitzer-Williams" <noahsw@cyberdude.com> wrote in message
news:20010705132745.31408.qmail@pb1.pair.com...
> i have two tables each with a same field and i would like to find which
> table has the bigger value in this field..
>
> is there a way to do this with one select statement?
>
> i've tried things like:
> select max(t1.bannerid) as b, max(t2.bannerid) as a,
> IF(t1.bannerid>t2.bannerid,t1.bannerid,t2.bannerid) FROM user_banners as
t1,
> user_banners_approve as t2 ORDER BY t1.bannerid DESC GROUP BY t1.bannerid
>
> but im not having much luck.
Uh... either do a separate select for each table, or find a way to JOIN the
tables?
Better than that, if you're doing what it looks like you're doing - keeping
two separate tables, one for approved banners and one for non-approved
one? - make a single "banners" table with an 'approved' field... then it's
simple.