help in changing a query to retrieve random limited rows

I’d like to change this query in my WordPress plugin so that it retrieves 30 random rows out of 100.

$query = $wpdb->prepare( ”

SELECT p.*, qq.quiz_id, qq.question_order AS `order`
FROM {$wpdb->posts} p
INNER JOIN {$wpdb->prefix}learnpress_quiz_questions qq ON p.ID =
qq.question_id
WHERE qq.quiz_id IN(” . join( ‘,’, $format ) . “)
AND p.post_status = %s

“, $args );

I’ve changed it to this but it still does not work. Could any body help me ,please?

SELECT p.*, qq.quiz_id, qq.question_order AS `order`
FROM {$wpdb->posts} p
INNER JOIN {$wpdb->prefix}learnpress_quiz_questions qq ON p.ID = qq.question_id
WHERE qq.quiz_id IN(” . join( ‘,’, $format ) . “)
AND p.post_status = %s
order by RAND() LIMIT 30

Read more here:: help in changing a query to retrieve random limited rows

Leave a Reply

Your email address will not be published. Required fields are marked *