PDA

View Full Version : join problem


bazz
02-01-2008, 05:12 PM
Hi,

Finally got it. amongst other things, I hadn't got matching FK in the Db.:( Still; I know the query works :)

I have a select which works until I add the where clause. what am I getting worng please.


my $Path = 'P';
my $varToMatch = $Path.'%';

my $sth = $dbh->prepare("SELECT BD.business_id, BD.business_address_id, BD.group_name ADDR.city_or_county_name
FROM tbl_businessDetails BD
WHERE BD.group_name LIKE '$varToMatch'
INNER JOIN tbl_address ADDR
ON BD.business_address_id = ADDR.address_ID
")
or die "prepare statement failed: $DBI::errstr\n";



error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN tbl_address ADDR
ON BD.business_address_id' at line 4 at input_new_business.pl line 156.

MySQL v5.0.45

bazz

oesxyl
02-01-2008, 10:08 PM
try this:


$query = "select bd.business_id, bd.bussiness_address_id, bd.group_name,
addr.cyty_or_county_name
from tbl_businessDetails as bd, tbl_address as addr
where bd.business_address_id = addr.address_ID and
bd.group_name like '" . $varToMatch . "'";


best regards