How can I improve rand()...rand() too slow

Good Day,

Am trying to improve rand() method in my Mysql syntax because rand() is too slow but am facing some issue with the right syntax to use… below is the sql

$sql= "SELECT artist_username,artist_bizname,artist_city,artist_state,artist_country,members_signup.profile_photo 
FROM artists INNER JOIN members_signup ON artists.artist_username = members_signup.user_name
WHERE artists_id >= (SELECT FLOOR( MAX(artists_id) * RAND()) FROM `artists` 
MATCH(artist_str) AGAINST(:phrase) OR
MATCH(artist_city) AGAINST(:phrase) OR
MATCH(artist_state) AGAINST(:phrase) OR
MATCH(artist_country) AGAINST(:phrase) OR
MATCH(artist_username) AGAINST(:phrase) 
)ORDER BY artists_id";
$s = $pdo->prepare($sql);
$s->bindValue(":phrase", $srhArtistVal);
$s->execute();

each time I get syntax error message

check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘MATCH() AGAINST(’) OR MATCH() AGAINST( at line 4 in

You’re missing a WHERE in your subquery

$sql= "SELECT artist_username
			, artist_bizname
			, artist_city
			, artist_state
			, artist_country
			, members_signup.profile_photo 
		 FROM artists 
		INNER JOIN members_signup ON artists.artist_username = members_signup.user_name
		WHERE artists_id >= (SELECT FLOOR(MAX(artists_id) * RAND()) 
							   FROM artists
							  WHERE MATCH(artist_str) AGAINST(:phrase) 
								 OR MATCH(artist_city) AGAINST(:phrase) 
								 OR MATCH(artist_state) AGAINST(:phrase) 
								 OR MATCH(artist_country) AGAINST(:phrase) 
								 OR MATCH(artist_username) AGAINST(:phrase))
		ORDER BY artists_id";

@DaveMaxwell Thanks for your time…problem solve.

2 Likes

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