You said:

...this yields Cartesian results, creating duplicate values for Image records when there's no match in the Images table for values in the joined ones.

I'm not sure I understand what you mean there, but it sounds like you don't understand what "Cartesian" means in this context. You are querying for all columns from a set of joined tables, and when table A has two or more rows related to a single row of table B, the values from that row of B will have to be repeated for each matching row in A. That's the Cartesian product you get from doing that sort of join.

If you only want one row of output for each row in the Images table, you either don't want to join with tables that contain multiple matches to a given Images row, or else you want to select some sort of grouped or aggregate value from those other tables, so that there is only one value from each table to be returned for each row of Images -- e.g.:

SELECT ImageID,ImageName, Regio.RegioID,RegioName, Insula.InsulaID,InsulaName, Sources.SourceID,SourceName, (etc...), COUNT(ThemeID) FROM Images LEFT JOIN Regio ON Images.RegioID = Regio.RegioID LEFT JOIN Insula ON Images.InsulaID = Insula.InsulaID LEFT JOIN ImgThemes ON Images.ImageID = ImgThemes.ImageID LEFT JOIN Sources ON Images.SourceID = Sources.SourceID GROUP BY ImgThemes.ImageID ORDER BY ImageName LIMIT $start,$numrows"
Note the addition of the "GROUP BY" clause, and the use of the "COUNT()" function for returning a single value for all rows in the ImgThemes table that match a given Image row.

(update: fixed typo in field list of select statement)


In reply to Re: DBI MySQL Join Question by graff
in thread DBI MySQL Join Question by Jazz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.