Is it possible to order by a selected columnname?

  SELECT * FROM tablex ORDER BY  quote_ident((
  select column_name from information_schema.columns
  where table_name = tablex AND column_name LIKE 'Index')) ASC;

The output of this is not ordered according to the columnname Index.

So basically my question is if i can use a select query in the order by clause like this simple one:

SELECT * FROM tablex ORDER BY (SELECT Index FROM table WHERE....);

What did i oversee?

  • No, that's not possible - at least not with plain SQL – a_horse_with_no_name Jul 25 at 13:43
  • How can I implement it then? Are there any other ways to do this? – DataLordDev Jul 25 at 13:45
  • ... select column_name ... where column_name LIKE 'Index' - are you serious? – Akina Jul 25 at 18:59
  • was just a test i want to search for LIKE 'Index_18%' something like this – DataLordDev Jul 26 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.