Hi guys, I have average PHP skills (and still learning) but very low Mysql skills. And really need help with this new project I've taken on. What I need to do is select from a table that has 50 (50 rows) questions in. This selection needs to be random which I can do using ORDER BY RAND() LIMIT $i. However I also need to select 'mandatory' (all mandatory questions need to be displayed) questions from the same table, these are marked as mandatory within the table. So in a nut shell I need to select and display all of the mandatory question and then randomly select from the rest of the questions, but not displaying all of them (LIMIT maybe) and no repeat questions to display. At the moment I've tried: SELECT * FROM `fuel_1` WHERE man='1' UNION ALL SELECT * FROM `fuel_1` WHERE man='0' ORDER BY RAND() LIMIT 6 Code (markup): But this just displays 6 random questions, not all of the manatory questions and then a set amount of non manatory questions. Many thanks for your help in advance
Maybe something like this: SELECT * FROM `fuel_1` WHERE man='1' OR id IN( SELECT id FROM `fuel_1` WHERE man='0' ORDER BY RAND() LIMIT 6 )
Thanks for the reply jestep As it happends the below code did work, I was adding it to a variable wrong SELECT * FROM `fuel_1` WHERE man='1' UNION ALL SELECT * FROM `fuel_1` WHERE man='0' ORDER BY RAND() LIMIT 6 Code (markup): Many thanks