Unix Technical Forum

JOIN Query

This is a discussion on JOIN Query within the MySQL forums, part of the Database Server Software category; --> I am need to lookup the email address or login in table A along with it's corresponding userid in ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:42 AM
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:42 AM
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')


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com