3 Replies - 2093 Views - Last Post: 20 January 2006 - 06:39 AM

#1 rockincoder  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 33
  • Joined: 15-November 03

Putting data together from 2 tables

Posted 19 January 2006 - 05:18 PM

Hi again,
I have a database with 2 tables: agents_anderson and agents_oconee
each table is identical except for the data
They both contain the columns: first and last
Im trying to populate a dropdown menu with the first and last name of all the agents from both tables, and i cant seem to get the correct query to add all the data together. Here is my code minus the query.
What am i doing wrong, it doesnt return anything.

<? 
$sql = "(SELECT first, last FROM agents_anderson) UNION (SELECT first, last FROM agents_oconee) ORDER BY last ASC";
$result = mysql_query($sql,$dbconnect); 
?>
<select name="agent">
<? while ($row = mysql_fetch_assoc($result)) { ?>
<option value="<?=$row['first']."&nbsp;".$row['last']?>">
<?=$row['first']."&nbsp;".$row['last']?>
</option>
<? } ?>
</select>



Is This A Good Question/Topic? 0
  • +

Replies To: Putting data together from 2 tables

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Putting data together from 2 tables

Posted 19 January 2006 - 07:32 PM

Looks fine to me...I don't usually use the brackets, but I just ran the following:
SELECT fname,lname
FROM `name1` UNION
SELECT fname,lname FROM name2 order by lname asc

and it worked fine for me. Have you tried appending an 'or die(mysql_error))' to the execution of the query to ensure that the query itself is running? Try using the mysql_fetch_array() function (not that it should matter).
Was This Post Helpful? 0
  • +
  • -

#3 rockincoder  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 33
  • Joined: 15-November 03

Re: Putting data together from 2 tables

Posted 19 January 2006 - 07:55 PM

I think i figured it out, mysql is 3.23 on the server my work uses, and if i read right union is after 4.0. Is there any other way to do what im trying to do without updating mysql?
Was This Post Helpful? 0
  • +
  • -

#4 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: Putting data together from 2 tables

Posted 20 January 2006 - 06:39 AM

Try using UNION ALL instead.
That might work.

Here, the Oracle Forum has the Question answered (sort of).

Otherwise...you have to upgrade.

This post has been edited by born2c0de: 20 January 2006 - 06:45 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1