Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query Question

Participant ,
Sep 16, 2009 Sep 16, 2009

I have a table with 4 columns I want to sort and not sure how.

I can sort by 1 column but I need the sort to be on 2 columns.

Here are the 4 columns

City1
City2Rate1Rate2
DallasMentor10065
RichmondNew York9560
MiameHouston125116
EnidDenver4038

I want to sort them using the UNION of the values in the RATE1 and RATE2 columns

So I want them sorted like this

Miame 125

Houston 116

Dallas  100

Richmond 95

Mentor 65

New York 60

Enid  40

Denver 38

Any Help

TOPICS
Database access
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Sep 25, 2009 Sep 25, 2009

weird table IMO. Well, as already said you didn't specify which DB you are using but in Oracle you can try:

SELECT City1,

              Rate1

  FROM  myTable

UNION

SELECT City2,

              Rate2

  FROM  myTable

ORDER BY 2 DESC

Translate
LEGEND ,
Sep 16, 2009 Sep 16, 2009

SQL questions are probably best asked on an SQL forum, but no matter.

It might help to read the docs for your DB of choice, because this will all be covered there (reading the docs is always a good way to find out how to do something, btw 😉

Anyway, the piece of the puzzle that you are missing here is that one can specify more than one column in an ORDER BY statement.

I can't point you to the relevant docs because you don't say which DB system you're using, but it'll be in there, as well as examples and what not.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 25, 2009 Sep 25, 2009
LATEST

weird table IMO. Well, as already said you didn't specify which DB you are using but in Oracle you can try:

SELECT City1,

              Rate1

  FROM  myTable

UNION

SELECT City2,

              Rate2

  FROM  myTable

ORDER BY 2 DESC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources