Click to See Complete Forum and Search --> : dupplicates


ricosushi
11-15-2007, 05:46 PM
Hi


I do this query and i get dupplicates in my result. What i want is to have only 1 result of each.



on this query:


$sql = "SELECT a.nombre,
u.ubicacion
FROM aviso a, usuario_aviso u
WHERE a.activo != '0' ";





please help me out.

thanks

mattyblah
11-15-2007, 09:45 PM
$sql = "SELECT distinct a.nombre,
u.ubicacion
FROM aviso a, usuario_aviso u
WHERE a.activo != '0' ";

chazzy
11-16-2007, 06:38 AM
This is a bad situation to use a distinct.
The reason you get duplicates is because you're not setting up any relationship between a and u in your query. is there some kind of foreign key relationship between the two tables?

mattyblah
11-16-2007, 10:44 AM
bah, didn't even notice that. it is doing a cross join. my bad. the OP should specify which columns to join on.

ricosushi
11-16-2007, 12:44 PM
I set the relation and it worked just fine :).


Just to let you know heres the code:




$sql = "SELECT aviso.nombre, aviso.id, aviso.fecha,
usuario_aviso.ubicacion
FROM aviso, usuario_aviso
WHERE aviso.activo != 0
AND aviso.usuario = usuario_aviso.id";




Thanks both of you