PDA

View Full Version : SQL query outputting too much


bazz
02-17-2008, 09:41 PM
Hi,

I have the query below which seems to ignore the 'where' clause. Instead of bringing in the data from a specificed area/locality, it seems to bring it all in.


my $sth = $dbhconnect->prepare ("SELECT DISTINCT BD.group_name
FROM tbl_businessDetails BD, tbl_address ADDR
WHERE ADDR.city_or_county_name = '$search_area'
") or die "prepare statement failed: $DBO::errstr\n";


$sth->execute;



Any pointers as to what I am missing here would be gratefully appreciated

bazz

BubikolRamios
02-18-2008, 03:11 AM
missing left join, right join, .....

oesxyl
02-18-2008, 11:14 AM
SELECT DISTINCT BD.group_name
FROM tbl_businessDetails BD, tbl_address ADDR
WHERE ADDR.city_or_county_name = '$search_area'


your are geting data from two tables with no relation defined between them.
the query return all the row from BD and all the row from ADDR which match the where condition.
As BubikolRamios say you must have a join from BD to ADDR or from ADDR to BD or some where clause.

best regards