0

let's say i hae a table schema named person it has these columns listed below

id  |  name  | age  | gender | activities_in_order | created_date

the value for activities_in_order column is a boolean...true or false..

how to use this column as reference in a select statement itself ?

here's my pseudo code

SELECT * FROM Person   ( if activities_in_order = true ORDER by field_here else if activities_in_order = false Order By field_here ) 
1
  • 2
    This doesn't really make sense. The ORDER BY is applied to all rows from the result. The value of the column might change for every row. Please edit your question (by clicking on the edit link below it) and add some sample data and the expected output based on that data as formatted text. See here for some tips on how to create nice looking text tables. (edit your question - do not post code or additional information in comments) Commented Jul 30, 2020 at 8:39

1 Answer 1

2

Try this:

select * from "Person"
order by
  case when activities_in_order then field_here else field_there end;

Maybe your data design can be improved though.

Sign up to request clarification or add additional context in comments.

1 Comment

This is right. The only problem will be if field_here and field_there are different datatypes.

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.