query is ignoring where clause
Posted by:
Tom Cat
Date: November 18, 2015 08:46AM
This isn't really a newbie question but I didn't see a forum for SQL help. Hope it is ok to post here.
I have a table:
CREATE TABLE `the_numbers` ( `the_number` int(3) NOT NULL ) ;
with the following data
INSERT INTO `the_numbers` (`the_number`) VALUES (1),(2),(4),(5);
When I do the following query it often gives me values that should be excluded by the where clause:
SELECT floor(rand()*5) as 'rndnum' from the_numbers where 'rndnum' not in (SELECT the_number from the_numbers) limit 1
That is to say I'll more often than not the query will return 1,2, or 4 instead of always returning 0 or 3.
What am I doing wrong?
Also my intention is to produce a random number that is not repeated so if there's a better way of doing that, please let me know.
Thanks in advance.
Subject
Written By
Posted
query is ignoring where clause
November 18, 2015 08:46AM
November 18, 2015 12:38PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.