Hello, I have got two tables. One of them is about the videos and the other one is about the ratings for that videos. I want to display the videos by the ratings. How can i make a query to do this? This is the query to display videos by most visited $sql = "select uniq_id, artist, video_title, yt_views, site_views, added FROM pm_videos WHERE category LIKE '%$catid%' ORDER BY yt_views DESC LIMIT 50" ; Code (markup): the table for the ratings is called: pm_ratings and connected to pm_videos by id. Thank you for your help.
i think there is a default command " join " .. but i don't know how to use but you can search in php.net..
Try this: $sql = "select category.uniq_id, category.artist, category.video_title, category.yt_views, category.site_views, category.added FROM pm_videos, pm_ratings WHERE pm_ratings.id=pm_videos.id AND category LIKE '%$catid%' ORDER BY pm_ratings.rating DESC LIMIT 50" ; PHP: Brew
Please let me know the columns in each of the two tables and the columns you want displayed in the output of the query cheers, jay
pm_ratings has got id, total_votes, total_value. pm_videos has got id, uniq_id. They are connected to each other by id and uniq_id pm_videos uniq_id is pm_ratings id. I want to show the videos by total_value thanks
Try: [COLOR="Blue"]$sql = [COLOR="Red"]"SELECT a.id, uniq_id, total_value FROM pm_videos a, pm_ratings b WHERE a.uniq_id = b.id ORDER BY total_value DESC"[COLOR="Blue"] ;[/COLOR] [/COLOR][/COLOR] Code (markup):
I am giving simple example and also generalize that will able to solve your problem. Say table TA: id, val1, val2; table TB: id, val3,val4. Then the query is: Select a.*, b.* from TA a inner join TB b where a.id=b.id Thus you can use joining inner, left outer, right outer, full outer or cross joining. But inner join is most necessary, also 2nd and 3rd.
Baris22, any reputation point for my post above, if it really helped you ? I am very new here and any reputation point earned will be of great help. Thanks. cheers, jay