Welcome Guest, Not a member yet? Register   Sign In
MySQL Query Two Tables Help
#1

[eluser]tribalab[/eluser]
I'm trying to find the most effecient way to list messages sent to a user, but cross reference two tables to resolve userids that are used in the mail table with the names stores in the users table.

here are two simple tables:

USERS: [ ID, FIRSTNAME, LASTNAME ]
MAIL: [ TO, FROM, STATUS, SUBJECT, MESSAGE, DATE ];

The mail.to and mail.from are the respective users.id values. I'd like to do a single query to get all entries in mail where status='unread', but in addition to getting the id's for each message, I would like to get the users' firstname+" "+lastname as well.

So something like a combo of:
"SELECT * FROM mail WHERE mail.to=1" & foreach... "SELECT firstname, lastname FROM users WHERE id=".$mailfrom

Thanks for the help!

Aaron


Messages In This Thread
MySQL Query Two Tables Help - by El Forum - 09-27-2007, 03:16 AM
MySQL Query Two Tables Help - by El Forum - 09-27-2007, 03:57 AM
MySQL Query Two Tables Help - by El Forum - 09-27-2007, 04:49 PM
MySQL Query Two Tables Help - by El Forum - 01-08-2013, 03:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB