0

I have a database "videos". Which has a table for each video i.e "ID" "Name" "Link" "Count". i want to be able to take the highest value of any of the tables from the column "Count" and then use which ever has the highest values "Link" Column.

So the best way i can explain is i'm trying to make a "Most Viewed" part of my site so which ever has the highest hit count gets displayed via $row['link'].

Hope this made sense didn't much to me!

Thanks all in advance...

midicharm
  • 5
  • 2
  • 1
    "Hope this made sense didn't much to me! " -erm, what? – Mitch Wheat Aug 15 '13 at 11:31
  • 2
    It didn't make sense. But `SELECT * FROM your_weird_table ORDER BY Count DESC LIMIT 5` should give you your 5 (or how many you want) records of videos. Also, don't use MySQL reserved words for column names (count is a reserved word, name is a reserved word). – N.B. Aug 15 '13 at 11:32

2 Answers2

1
SELECT `id`,`name`,`link`,`count` from my_table order by `count` desc limit 5;

This will give you 5 most viewed links.

Tip : You should not use words like count as column names as they are MySQL keywords.

DhruvPathak
  • 42,059
  • 16
  • 116
  • 175
0
SELECT `link` FROM `someTable` ORDER BY `Count` DESC LIMIT 1

This will give you the link of the row with the highest count.

MajorCaiger
  • 1,893
  • 1
  • 12
  • 18