stallion
stallion

Reputation: 1987

query to sort rowwise in sql

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

Upvotes: 1

Views: 359

Answers (1)

ppeterka
ppeterka

Reputation: 20726

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

Upvotes: 3

Related Questions