Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2015

    Unanswered: Difficult Sql Query


    Can anyone please explain me the following difficult sql query

    $popular_sql = "select * from tubeblue_videos join (select ceil (rand() * (select max(video_id) from tubeblue_videos)) as vid from tubeblue_videos group by category_name) as rnd where video_id=vid limit 54";


    Vishal Ved

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    The logic behind this SELECT statement seems pretty sketchy to me, I can't explain the logic behind the choice even though I understand what it does. It would probably help you to understand it if you looked at it properly formatted.

    SELECT *
       FROM tubeblue_videos
       JOIN (SELECT ceil (rand() * (SELECT max(video_id) FROM tubeblue_videos)) AS vid
          FROM tubeblue_videos group by category_name) AS rnd
       WHERE video_id=vid
       LIMIT 54
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts