2

enter image description here

I have tried this code but it is not working.

$select=$conn->query("select * from tbl_testquestion ORDER BY SUBSTRING( type_id=0 qu_id RAND() ) , type_id=1 qu_id ASC");

please suggest edit if question not reached the standards

1 Answer 1

2

you'll want to use a case statement

SELECT *      
FROM tbl_testquestion 
ORDER BY 
    CASE 
        WHEN type_id=0 THEN RAND() 
        WHEN type_id=1 THEN qu_id 
    END ASC 
Sign up to request clarification or add additional context in comments.

1 Comment

yeah, upped - the title is a little hard to understand, maybe change it to "mysql query: ordering by different column depending on value of another column"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.