Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: DBI MySQL Join Question

by ELISHEVA (Prior)
on Oct 05, 2009 at 04:49 UTC ( [id://799159]=note: print w/replies, xml ) Need Help??


in reply to DBI MySQL Join Question

Hmmm. I think you may have the left join backwards. As written it is taking the cartesian product of Insula and Regio and then joining it to Image whenever there happens to be an image record that has that particular combination of Insula and Regio.

The table after the words "LEFT JOIN" is the table from which you want to select all records even if they have a NULL value in one or more foreign key fields. If you want to take each Image record and join it to Regio and Insula wherever possible, then you need to swap the first two LEFT JOINs, like this:

my $sth = $dbh->prepare( "SELECT * FROM Images LEFT JOIN Images ON Images.RegioID = Regio.RegioID LEFT JOIN Images ON Images.InsulaID = Insula.InsulaID LEFT JOIN ImgThemes ON Images.ImageID = ImgThemes.ImageID LEFT JOIN Sources ON Images.SourceID = Sources.SourceID ORDER BY ImageName LIMIT $start,$numrows" );

Best, beth

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://799159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found