Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MySQL (http://www.go4expert.com/forums/mysql-forum/)
-   -   Merging two tables in mysql query ! (http://www.go4expert.com/forums/merging-tables-mysql-query-t5318/)

coool 17Jul2007 22:19

Merging two tables in mysql query !
 
Hi :)

let's say I have two database tables

FruitsTable
Id..........name..........color
13..........a..................green
25..........k..................yellow
32..........o..................red

VegetablesTable
Id..........name..........color
13..........d..................green
25..........g..................white
32...........l..................red

now can I do that ?

PHP Code:

<?php

$fields
="Id,name";
$tables="FruitsTable,VegetablesTabes";
$conditions="color in 'green,red'";

$sql="SELECT $fields FROM $tables WHERE $conditions";
?>

error: Id is ambiguous !! :eek:

shabbir 18Jul2007 09:10

Re: Merging two tables in mysql query !
 
No you cannot do that and you are surely to get that error. Can you tell me what does Id mean in your $fields variable. I mean for which table it refer to. I cannot get that and so should the database will not be. Make it explicit like "FruitsTable.Id" or "VegetablesTabes.Id";

coool 27Jul2007 00:53

Re: Merging two tables in mysql query !
 
I've got the problem solved by using UNION :)

Thanks


All times are GMT +5.5. The time now is 22:42.