Leif,

> I want to select and join data from two tables if the same id exists
in both
> tables.  If the id only exists in one table I want MySQL to return a
string
> like "sorry, no records found".  How can I do this?
>
> I'm guessing it's something like:
>
> mysql> SELECT tbl1.this, tbl2.that FROM tbl1, tbl2 WHERE IF (tbl1.id =
> tbl2.id, return the data, "no record");
>
> (Obviously that's not a real query).


Close though! I'm assuming that tbl2's population is a sub-set of that
in tbl1 (otherwise what will you do when tbl2 throws up a row that has
no tbl1 equivalent). Herewith a solution using my own tblNms:

SELECT Jfull.Id, Jfull.Word,
    IF( Jsubset.Word > '', Jfull.Word, 'no record' ) AS Data
  FROM Jfull LEFT OUTER JOIN Jsubset USING ( Id )

Regards,
=dn


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to