This is a discussion on JOIN Query within the MySQL Database forums, part of the Database Forums category; I am need to lookup the email address or login in table A along with it's corresponding userid in ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am need to lookup the email address or login in table A along with
it's corresponding userid in the same table. I then need to take that userid, and search for it in table B. Since I am searching for a number of email addresses, I was trying to use IN to create a group. My original query looked like this: SELECT tableA.mail, tableA.login, tableA.userid, tableB.firmname, tableB.address, tableB.phone, tableB.userid FROM `tableA`,`tableB` WHERE tableA.mail IN (`email1@email.com`, `email2@email.com`, `email3@email.com`) OR tableA.login IN (`email1@email.com`, `email2@email.com`, `email3@email.com`) Then I tried a JOIN version: SELECT `userid`, tableB.firmname, `tableB.address`, `tableB.phone`, FROM `tableA` JOIN `tableB` ON (tableB.userid=tableA.userid) WHERE tableB.userid=tableA.userid) I just need to be able to find the userid of an email address in table A and then lookup that userid in table B. Your help is appreciated. |
|
|||
|
Jerim79 wrote:
> I am need to lookup the email address or login in table A along with > it's corresponding userid in the same table. I then need to take that > userid, and search for it in table B. Since I am searching for a > number of email addresses, I was trying to use IN to create a group. > My original query looked like this: > > SELECT tableA.mail, tableA.login, tableA.userid, tableB.firmname, > tableB.address, tableB.phone, tableB.userid FROM `tableA`,`tableB` > WHERE tableA.mail IN (`email1@email.com`, `email2@email.com`, > `email3@email.com`) OR tableA.login IN (`email1@email.com`, > `email2@email.com`, `email3@email.com`) > > Then I tried a JOIN version: > > SELECT `userid`, tableB.firmname, `tableB.address`, `tableB.phone`, > FROM `tableA` JOIN `tableB` ON (tableB.userid=tableA.userid) WHERE > tableB.userid=tableA.userid) > > I just need to be able to find the userid of an email address in table > A and then lookup that userid in table B. Your help is appreciated. > your join sql does not look right. can you try something like this: SELECT tableA.userid, tableB.firmname, tableB.address, tableB.phone FROM `tableA` JOIN `tableB` ON (tableB.userid=tableA.userid) WHERE tableA.mail = 'email1@email.com' OR tableA.login = 'email1@email.com' alternatively you can do this if you have more than value you're looking for: SELECT tableA.userid, tableB.firmname, tableB.address, tableB.phone FROM `tableA` JOIN `tableB` ON (tableB.userid=tableA.userid) WHERE tableA.mail IN ('email1@email.com' , 'email2@email.com') OR tableA.login IN ('email1@email.com', 'email2@email.com') |