Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query two databases with one query

Status
Not open for further replies.

krappleby025

Programmer
Joined
Sep 6, 2001
Messages
347
Location
NL
hi all

i have two databases

au_primary_hits
users

now

i need to select the top 10 users, from the au_primary_hits table where the 'extra3' field in the users table is equal to a set code. IE 'topguns'

currently i have this

select * from ua_primary_hits where Month = '$chosenmonth' and Year = '$chosenyear' order by Month_Unique Desc LIMIT 10

which only selects the top 10 users from the au primary hits table.. Now i need to edit that.

now i need to merge that query to the one below

select * from users where extra3 = 'topguns'

so what i end up with is something like

select * from ua_primary_hits where ('users' field extra3 = 'topguns') and Month = '$chosenmonth' and Year = '$chosenyear' order by Month_Unique Desc LIMIT 10

any help would be appreciated, As i am only a beginner at this

Thank you for your help

keith
 
2 dbs or 2 tables? it makes a lot of difference...
 
you need to have a key that links the two tables with one another (let's say both table have a field called username)
try this:
Code:
select * from users a join ua_primary_hits b on (a.username=b.username) where a.extra3='topguns' and b.Month = '$chosenmonth' and b.Year = '$chosenyear' order by b.Month_Unique Desc LIMIT 10
 
Thanks Dazzled, I will try that later. today.. if it works you get a star. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top