Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help with a complex SQL query

Author  Topic 

lazyme
Starting Member

8 Posts

Posted - 2009-10-08 : 20:12:03

I am trying to solve the following query; it has 3 tables


Tags Table

user tags

u1 Los Angeles, Real good
u2 Real good
u2 Madrid
u5 Madrid, Milan
u2 Rossoneri
u6 Milan, Los Angeles
u5 Los Angeles


Location Table

user_id location_id
u1 loc1
u2 loc1
u3 loc2
u4 loc2
u5 loc1
u6 loc3
u7 loc1

Country Table

location_id country
loc1 Spain
loc2 England
loc3 Spain
loc4 USA
loc5 Italy
loc6 USA
loc7 USA


Now I want to write an sql query which displays the most seen tag(s) for each country. How can I achieve this?

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2009-10-08 : 20:31:35
What is this for?

=================================================
Creating tomorrow's legacy systems today. One crisis at a time.
Go to Top of Page

lazyme
Starting Member

8 Posts

Posted - 2009-10-08 : 21:49:01
I have got internship in a firm and they have asked me to brush up on my SQL skills. I have taken some basic SQL tutorials and was practicing a few queries when I came across this one.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-10-09 : 02:59:56
Give it a shot and see what you can get out of it by yourself first. If you need the basics this is a really good place to start: http://www.w3schools.com/SQl/default.asp

- Lumbago
http://xkcd.com/327/
Go to Top of Page

jason97m
Starting Member

4 Posts

Posted - 2009-10-12 : 04:13:01
I would begin with an embedded query within a query....in other words, count each tag's occurence, then do another select to get each country associated with the tag, and output the country name with the count result for that country.

Jason Morris
BRIXTON.US
Go to Top of Page
   

- Advertisement -