Here's a situation I've run into more than once with SQL:
I want to select all the rows in a table that match a criteria, where one
of the criteria is possibly having a related entry in a second table. For
my example, lets say I have table named 'messages' and another named
'message_attachments'. The former has a primary key of msg_id, the latter
also contains msg_id, and has an attachment_id as it's primary key.
This statement shows me all the messages that also have attachments:
SELECTmessages.msg_id,message_attachments.attachment_idFROM messages,message_attachmentsWHERE messages.msg_id =
message_attachments.msg_id;
But I want a statement that says: "Show me all the messages, and include
information about an attachment if they have one"
(Let's further assume that a message will have only one attachment).
Is this possible? Anyone like to share an example? Much thanks.
-mark
http://mark.stosberg.com/