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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. help writing query

help writing query

Scheduled Pinned Locked Moved Database
questiondatabasehelp
5 Posts 4 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.
  • M Offline
    M Offline
    michaelgr1
    wrote on last edited by
    #1

    Hello, I write a query (combine of 2 queries using UNION): query1 UNION query2 I want the result of query 2 (there is only one result in query2) will be placed in the last row of the results of the big query. I mean the results of query1 will be in the first rows and the result of the query2 will be in the last row. How can i do it?

    B A 2 Replies Last reply
    0
    • M michaelgr1

      Hello, I write a query (combine of 2 queries using UNION): query1 UNION query2 I want the result of query 2 (there is only one result in query2) will be placed in the last row of the results of the big query. I mean the results of query1 will be in the first rows and the result of the query2 will be in the last row. How can i do it?

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Example select * from table1 union select * from table2


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      M 1 Reply Last reply
      0
      • B Blue_Boy

        Example select * from table1 union select * from table2


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        M Offline
        M Offline
        michaelgr1
        wrote on last edited by
        #3

        OK, I know that. But the problem is that the results are mixed. I want the results of the second query will be the last (in the last rows of the result big table)

        D 1 Reply Last reply
        0
        • M michaelgr1

          Hello, I write a query (combine of 2 queries using UNION): query1 UNION query2 I want the result of query 2 (there is only one result in query2) will be placed in the last row of the results of the big query. I mean the results of query1 will be in the first rows and the result of the query2 will be in the last row. How can i do it?

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          The easiest way I know of is to introduce a sorting column

          select '1' as seq,* from table1
          union
          select '2' as seq from table2
          order by seq

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          1 Reply Last reply
          0
          • M michaelgr1

            OK, I know that. But the problem is that the results are mixed. I want the results of the second query will be the last (in the last rows of the result big table)

            D Offline
            D Offline
            David Mujica
            wrote on last edited by
            #5

            Remember that SQL unions are based on set theory, so if value A is from table 1 and value A is also from table 2 you would only get one value A is your result set. By introducing the sort indicator that "Ashfield" suggests, you would get 2 values of A. You would get 1,A and 2,A. I'm not sure if this would impact your algorithm, but I just wanted to make you aware of it. Cheers, David

            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