1

i have a table with say 2 columns of varchar type. i want to query to sort them rowwise in SQLlite.

eg: Table

COLUMN1  COLUMN2
book     apple
lemon    mango
google   amazon

the query should return me this:

apple    book
lemon    mango
amazon   google

1 Answer 1

3

In SQLite, you can do this using the MIN and MAX functions, as detailed here

SELECT MIN(column1, column2), MAX(column1, column2) FROM mytable

You originally didn't specify the DB type, so I wrote this for MySQL. The logic applies to others as well, though the functions may differ.

SELECT LEAST (column1, column2), GREATEST(column1, column2) FROM mytable
Sign up to request clarification or add additional context in comments.

1 Comment

Updated my answer for SQLite. And next time please tag your question with the DB you're using to get better specialised help and quicker...

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.