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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with SQL Query, it's kinda challenging 1

Status
Not open for further replies.

linkin123

Programmer
Oct 29, 2006
5
GB
ok basicly I have a table, which contain three columns:

ID | ID2 | ID3
--------------
1 5 6
2 3 8
3 3 7
4 3 9
5 25 18
--------------

the inputs will be ID3 (e.g. 7,9,18) i.e multiple inputs, not just one
the output needs to be: which is the most popular ID2, based on how many ID3 shared. sorted by popularity.
e.g. input of 7,9,8,18 will result in 3 and then 25

all i need is the SQL query, if you can help i would appreciate it
if you need more explanation, tell me.
thanks in advance
 
Hi

Sorry, I do not understand what you need. Just some tries :
Code:
[blue]mysql>[/blue] [b]select[/b] id2,id3 [b]from[/b] linkin123 [b]where[/b] id3 [b]in[/b] (7,9,8,18) [b]order by[/b] id2 [b]desc[/b];
+------+------+
| id2  | id3  |
+------+------+
|   25 |   18 |
|    3 |    8 |
|    3 |    7 |
|    3 |    9 |
+------+------+
4 rows in set (0.00 sec)

[blue]mysql>[/blue] [b]select[/b] id2,count(*) occurencies [b]from[/b] linkin123 [b]where[/b] id3 [b]in[/b] (7,9,18) [b]group by[/b] id2 [b]order by[/b] occurencies [b]desc[/b];
+------+-------------+
| id2  | occurencies |
+------+-------------+
|    3 |           2 |
|   25 |           1 |
+------+-------------+
2 rows in set (0.00 sec)

Feherke.
 
the second one is EXACTLY what I wanted, thank you so much
very much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top