santa
santa

Reputation: 12512

Order results with mySQL

If I have a table with data in the following format:

id  itemID  projectID   position_X   position_Y
________________________________________________
1    2677      10         -289         -27
2    2653      10         -403          253
3    337       10         -23          -77
4    2456      10          50           130 

and I need to create 3 different queries to output results as a list where:

  1. "X" axel is more important
  2. "Y" axel is more important
  3. Whatever makes more sense based on the chart

How would I do that?

enter image description here

Upvotes: 0

Views: 60

Answers (1)

DaveL
DaveL

Reputation: 339

Alright, given the comments on the OP, I would say your 3 queries would be something like:

  1. SELECT position_X, position_Y FROM <tablename> ORDER BY position_X DESC, position_Y DESC;
  2. SELECT position_X, position_Y FROM <tablename> ORDER BY position_Y DESC, position_X DESC;
  3. SELECT positon_X, position_Y FROM <tablename> ORDER BY <desiredcolumn> DESC;

(Keeping in mind I don't know the table name, or the exact sort order of the third query)

Given the data you've posted, outputting these three queries in order would give you:

First Query:

50, 130

-23, -77

-289, -27

-403, 253

Second Query:

-403, 253

50, 130

-289, -27

-23, -77

(Query three isn't certain due to not having a decision on what sort order)

Upvotes: 2

Related Questions