Solved

SQL: Reorder Output columns?

Posted on 2011-09-07
8
370 Views
Last Modified: 2012-05-12
I am doing a cross join on 2 result sets that only have one row of information each (the first is returning a count and a sum, the second returns a count)

I would like to reorder the results set.

Currently the results are A, B, C

I would like it to be A, C, B

Is there a way to achieve what I would like?  A specific operator/command?
0
Comment
Question by:simplyfemales
  • 3
  • 3
  • 2
8 Comments
 
LVL 8

Expert Comment

by:Forefront_Data_Solutions
ID: 36499803
ORDER BY A, C, B
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 36499804

Just list the columns in the order you want

SELECT A, C, B
FROM TABA
CROSS JOIN TABB
0
 
LVL 8

Expert Comment

by:Forefront_Data_Solutions
ID: 36499808
As an example:

Select AB, CD, EF
From MyTable
Where AB='12'
Order by AB, EF, CD
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 8

Accepted Solution

by:
Forefront_Data_Solutions earned 500 total points
ID: 36499814
ahh, I think I misunderstood the question.  Just select the fields in the order that you want:

Select A, C, B
From MyTable
0
 

Author Closing Comment

by:simplyfemales
ID: 36499842
Forefront.  I was trying to overthink this.  Simply by nesting the whole thing and then selecting in the order I want is the easiest solution.

Thanks for the smack upside the head.  DOH!
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 36499848
Exactly how is that answer different from #36499804
0
 

Author Comment

by:simplyfemales
ID: 36499912
Ewangoya, I was probably a little vague in my question, but the cross tabs inclusion in your answer made my mind go in a different direction.  The answer from forefront bounced my mind to the nesting thought and that's why I gave it the solution.

I know I ask stupidly simplistic questions and you have helped me previously and I appreciate it very much.
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 36499916

No problem
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question