-1

Eg. In the Table1 there is a column ColName, some of the items in ColName are "Mike".

The code to search one of the them:

searchString = " SELECT * FROM Table1 WHERE ColName = 'Mike' "
cur.execute(searchString).fetchone()

The Problem: The code above allways gives me the first row, where "Mike" in ColName appears.

I actually want, by everytime running the sqlite code, to get a random search result from the column ColName, whose value is "Mike". How could I change the code?

Thanks for the help!

Rt Rtt
  • 595
  • 2
  • 13
  • 33

1 Answers1

0

If you want a random value, then you need to iterate over cur.execute(searchString) for some random amount, then extract the column(s).

fetchone() always returns the top result

The alternative includes trying to randomly sort the query results in SQL

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245