-1

I have 2 tables which i need to ranked of a certain genre list according to descending order.

Documentary(Title, Duration, language, Genre)

Rating(LoginNames, Rating)

I am suppose to create a list for a certain genre in descending order of the rating.

I came up with this:

SELECT * FROM Genre, Rating 
ORDER BY rank DESC

I am not to sure whether I will get the correct outcome of the result. Thank You!

Jacob H
  • 2,455
  • 1
  • 12
  • 29
Sun J
  • 17
  • 4
  • 1
    If you are trying to order by rating, wouldn't you... order by rating? – Jacob H Oct 26 '17 at 16:51
  • 2
    There doens't seem to be a field in both tables to join them. – isaace Oct 26 '17 at 16:53
  • I have to select a specific genre from the documentary and then rank it according to descending order. – Sun J Oct 26 '17 at 16:53
  • SunJ, what is the desired output? As @isaace pointed out, these tables cannot be joined together. I would assume that the Rating table needs a column for DocumentaryID (which I hope has a corresponding key in Documentary)? – kchason Oct 26 '17 at 16:55
  • @kchason@Jacob H, Oh yes i forgot to include that both has DocumentaryID as primary key which link both table together. Sorry for the omission. Thank you for pointing out – Sun J Oct 26 '17 at 16:57

1 Answers1

1

With your comment update:

SELECT
    DocumentaryTbl.Title,
    DocumentaryTbl.Genre,
    RatingTbl.Rating,
    ... -- I would avoid *, choose the columns you'd like
FROM
   Documentary AS DocumentaryTbl
LEFT JOIN
   Rating AS RatingTbl
   ON DocumentaryTbl.DocumentaryID = RatingTbl.DocumentaryID
ORDER BY
   RatingTbl.Rating DESC; -- Or whichever column(s) you want to sort by
kchason
  • 2,836
  • 19
  • 25
  • I am quite confused with the part after LEFT JOIN....., Do you mid to explain more in detail. Thank you! – Sun J Oct 26 '17 at 17:01
  • Which part is confusing you? From your comment, both tables have a `DocumentaryID`, which is how you're joining the tables. Whether you use `LEFT JOIN` or `INNER JOIN` depends on your desired behavior which you should look into in this question : https://stackoverflow.com/questions/17946221/sql-join-and-different-types-of-joins – kchason Oct 26 '17 at 17:03
  • The link you provided is in detail, I will read through the post, really appreciate your timing in answering this.Thank you! – Sun J Oct 26 '17 at 17:06