Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Ordered selection of 2 columns in single SQL query

Ordered selection of 2 columns in single SQL query

Scheduled Pinned Locked Moved Database
databasecollaborationhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Emmet_Brown
    wrote on last edited by
    #1

    Hey, I have a table named volleyballsecondround8 which has columns like 'Winner', 'Loser' and 'MatchNo'. I'd like to make a SELECT statement as it takes the 'Winner' where 'MatchNo'='M20' and puts it ind the [0]. row of my new table, then takes the 'Loser' of 'MatchNo'='M20' and puts it into the second row. Therefore; When I execute a query on volleyballsecondround8 like the following:

    Select @row := @row + 1 as row,Winner,Loser
    from volleyballsecondround8,(SELECT @row := 0) r
    Where MatchNo IN('M20','M19','M18','M17') Order

    I get e resultant table like: ROW-Winner-Loser ---------------- 1-India-Luxemburg 2-USA-Spain 3-Turkey-Argentina Where, I want a table like: ROW-TEAM ----------- 1-India 2-Luxemburg 3-USA 4-Spain 5-Turkey 6-Argentina any help?

    I 1 Reply Last reply
    0
    • E Emmet_Brown

      Hey, I have a table named volleyballsecondround8 which has columns like 'Winner', 'Loser' and 'MatchNo'. I'd like to make a SELECT statement as it takes the 'Winner' where 'MatchNo'='M20' and puts it ind the [0]. row of my new table, then takes the 'Loser' of 'MatchNo'='M20' and puts it into the second row. Therefore; When I execute a query on volleyballsecondround8 like the following:

      Select @row := @row + 1 as row,Winner,Loser
      from volleyballsecondround8,(SELECT @row := 0) r
      Where MatchNo IN('M20','M19','M18','M17') Order

      I get e resultant table like: ROW-Winner-Loser ---------------- 1-India-Luxemburg 2-USA-Spain 3-Turkey-Argentina Where, I want a table like: ROW-TEAM ----------- 1-India 2-Luxemburg 3-USA 4-Spain 5-Turkey 6-Argentina any help?

      I Offline
      I Offline
      i j russell
      wrote on last edited by
      #2

      SELECT Row,
      0 AS resultorder,
      Winner
      FROM volleyballsecondround8
      UNION ALL
      SELECT Row,
      1,
      Loser
      FROM volleyballsecondround8
      ORDER BY Row ASC, resultorder ASC

      E 1 Reply Last reply
      0
      • I i j russell

        SELECT Row,
        0 AS resultorder,
        Winner
        FROM volleyballsecondround8
        UNION ALL
        SELECT Row,
        1,
        Loser
        FROM volleyballsecondround8
        ORDER BY Row ASC, resultorder ASC

        E Offline
        E Offline
        Emmet_Brown
        wrote on last edited by
        #3

        thanks for help but I decided to take all the data to a DataTable and then sort it in the C# part of the project, the hard way =) thanks again

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups