sql - Special TABLE sorting -


i have 2 column table previous query this:

+--------+--------+ | id_no1 | id_no2 | +--------+--------+ |  1     |    2   | |  1     |    2   | |  1     |    3   | |  1     |    5   | |  2     |    1   | |  2     |    3   | |  2     |    3   | |  2     |    5   | |  3     |    1   | |  3     |    2   | +--------+--------+ 

the table order id_no1, id_no2

i want id_no1 , id_no2 paired this:

+--------+--------+ | id_no1 | id_no2 | +--------+--------+ |  1     |    2   | |  1     |    2   | |  2     |    1   | |        |        | |  1     |    3   | |  3     |    1   | |        |        | |  1     |    5   | |        |        | |  2     |    3   | |  2     |    3   | |  3     |    2   | |        |        | |  2     |    5   | +--------+--------+ 

id_no1 , id_no2 shops, sender , recipient. want group exchange between shops.

your requirement apparently sort data in order of parties involved. that, trying sort first lowest party involved (ascending), highest party involved (also ascending).

to done, wrote following: gives output in order you've shown, , work ... assuming wild guess remotely connected question.

/* sample data */      table1        (         select id_no1, id_no2                    ( values              (1,2),             (1,2),             (1,3),             (1,5),             (2,1),             (2,3),             (2,3),             (2,5),             (3,1),             (3,2)           ) value(id_no1, id_no2)       ) /* query */     select id_no1, id_no2            (         select              *,             case when id_no1 > id_no2 id_no1 else id_no2 end maxparty,             case when id_no1 < id_no2 id_no1 else id_no2 end minparty         table1       ) arr     order minparty, maxparty, id_no1 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -