JOIN Query

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-27-2007
Jerim79
 
Posts: n/a
Default JOIN Query

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.

Reply With Quote
  #2 (permalink)  
Old 04-27-2007
lark
 
Posts: n/a
Default Re: JOIN Query

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')


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0