dbTalk Databases Forums  

problems with table join

comp.databases.mysql comp.databases.mysql


Discuss problems with table join in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris Percol
 
Posts: n/a

Default problems with table join - 11-20-2010 , 02:06 PM






Hi, the following sql is not returning result I had hoped for
(obviously my problem and not the sql).

I would like to return an array as follows where booking and asset
tables are joined on weeknumber and only results for the current
weeknumber (php variable) are shown

[1] => Array
(
[teacher] => CM
[subject] => Applied Engineering
[yeargroup] => 12
[location] =>
[quantity] =>
)

$sql .= "SELECT booking.*,asset.location,asset.quantity FROM booking
";
$sql .= "LEFT JOIN asset ON booking.weeknumber = asset.weeknumber ";
$sql .= "AND booking.room = asset.room ";
$sql .= "AND booking.period = asset.period ";
$sql .= "AND booking.weeknumber = '$week_number'";

Many thanks,

Chris

Reply With Quote
  #2  
Old   
Doug Miller
 
Posts: n/a

Default Re: problems with table join - 11-20-2010 , 03:26 PM






In article <0c0a5855-3ad2-4a93-90d6-721b1e41195c (AT) e26g2000vbz (DOT) googlegroups.com>, Chris Percol <chris.percol (AT) gmail (DOT) com> wrote:
Quote:
Hi, the following sql is not returning result I had hoped for
(obviously my problem and not the sql).
It would be a lot easier to suggest how to fix it if you would tell us what
you were expecting to see.

Quote:
I would like to return an array as follows where booking and asset
tables are joined on weeknumber and only results for the current
weeknumber (php variable) are shown

[1] => Array
(
[teacher] => CM
[subject] => Applied Engineering
[yeargroup] => 12
[location] =
[quantity] =
)

$sql .= "SELECT booking.*,asset.location,asset.quantity FROM booking
";
$sql .= "LEFT JOIN asset ON booking.weeknumber = asset.weeknumber ";
$sql .= "AND booking.room = asset.room ";
$sql .= "AND booking.period = asset.period ";
$sql .= "AND booking.weeknumber = '$week_number'";

Reply With Quote
  #3  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: problems with table join - 11-21-2010 , 09:31 AM



On Nov 20, 8:06*pm, Chris Percol <chris.per... (AT) gmail (DOT) com> wrote:
Quote:
Hi, the following sql is not returning result I had hoped for
(obviously my problem and not the sql).

I would like to return an array as follows where booking and asset
tables are joined on weeknumber and only results for the current
weeknumber (php variable) are shown

[1] => Array
(
[teacher] => CM
[subject] => Applied Engineering
[yeargroup] => 12
[location] =
[quantity] =
)

$sql .= "SELECT booking.*,asset.location,asset.quantity FROM booking
";
$sql .= "LEFT JOIN asset ON booking.weeknumber = asset.weeknumber ";
$sql .= "AND booking.room = asset.room ";
$sql .= "AND booking.period = asset.period ";
$sql .= "AND booking.weeknumber = '$week_number'";

Many thanks,

Chris
Yo have neglected to tell us what you are actually getting nor what
teh data in the tables look like.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.