need help with mysql union

This is a discussion on need help with mysql union within the PHP General forums, part of the PHP Programming Forums category; hi, i'm trying to select * through 3 tables - is the following syntax correct? $sql="(SELECT * FROM mjp_cc)"; $...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-21-2003
r-militante@northwestern.edu
 
Posts: n/a
Default need help with mysql union

hi, i'm trying to select * through 3 tables - is the following syntax correct?

$sql="(SELECT * FROM mjp_cc)";
$sql="UNION";
$sql="(SELECT * FROM imc_cc)";
$sql="UNION";
$sql="(SELECT * FROM pmp_cc)";
$sql.=" ORDER BY savedccactivity DESC";

i basically just want to spit out the contents of these tables...

also - how would this type of query work if the name 'savedccactivity' is
different in all 3
tables?

thanks
redmond


Reply With Quote
  #2 (permalink)  
Old 07-21-2003
Cpt John W. Holmes
 
Posts: n/a
Default Re: [PHP] need help with mysql union

> hi, i'm trying to select * through 3 tables - is the following syntax
correct?
>
> $sql="(SELECT * FROM mjp_cc)";
> $sql="UNION";
> $sql="(SELECT * FROM imc_cc)";
> $sql="UNION";
> $sql="(SELECT * FROM pmp_cc)";
> $sql.=" ORDER BY savedccactivity DESC";
>
> i basically just want to spit out the contents of these tables...
>
> also - how would this type of query work if the name 'savedccactivity' is
> different in all 3
> tables?


This is a MySQL question, first of all.

Second, you need to rename the column in each table to 'savedccactivity' if
you want to order the whole result by that.

(SELECT foo AS column FROM table1)
UNION
(SELECT bar AS column FROM table2)
UNION
(SELECT abc AS column FROM table3)
ORDER BY column DESC

---John Holmes...

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:19 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0