Jump to content

table join


quasiman

Recommended Posts

Joining two tables - mail and mail_attachments.  I want to display all records where mail_attachments.message = mail.mailID.

I'm not getting any errors, but it's returning everything in the mail_attachments.name column, not just the records where my fields (above) are equal:

[code=php:0]
$query = "SELECT mail.mailID, mail_attachments.message, mail_attachments.name ".
"FROM mail, mail_attachments ".
"WHERE mail_attachments.message = mail.mailID";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
echo $row['name'];
echo "<br />";
}
[/code]
Link to comment
Share on other sites

eric1235711:
yes I'm sure there are records, and I have the names right.

thedarkwinter:
I tried your LEFT JOIN and I'm getting the same results.  For messages 2 and 3 there were two attachments each, so in the mail_attachments table there are four records.  I changed the row echo to display the attachment message number, my result then is:
2
2
3
3

I wonder if there's a script somewhere else on the page that's affecting this.  Is that possible?  I don't think so, but I can't see why it's doing this otherwise.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.