mercredi 7 avril 2021

How to select a random column from a database table

I have a database with columns friend id, movie 1 to movie 10. The database has recorded input from 4 people, each inputting 10 movies of their liking. My goal is to randomly select a movie from the database. Currently I have the following code:

SELECT *
FROM Project.movielist  
ORDER BY RAND ( )  
LIMIT 1  

The output is:

[(4, 2, 'Cars 1', 'Cars 2', 'Cars 3', 'Cars 4', 'Cars 5', 'Cars 6', 'Cars 7', 'Cars 8', 'Cars 9 ,'Cars 10')]

However, It only selects a random row. How would it select a random column (movie) in that row or any other rows.




Aucun commentaire:

Enregistrer un commentaire