How to select a random row in SQL accept selecting the rows of a unique key?

I am having trouble in finding the right code for my website. I want to fetch random row from a SQL data base using a PHP code and also I want the code to select any random row accept the row with a particular ID. This is the code that I came up with:

<?php
$sql = "SELECT column FROM table ORDER BY RAND() LIMIT 1";
?>

I want this code to select any row accept the row whose id = 1.

Thank you in advance for showing your interest.

This?

<?php
$sql = "SELECT column FROM table WHERE id <> 1 ORDER BY RAND() LIMIT 1";
?>

I might be wrong with ‘accept the row with id 1’
Do you mean including it or it must don’t be 1?

4 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.