Unix Technical Forum

Joining SQL Results

This is a discussion on Joining SQL Results within the SQL Server forums, part of the Microsoft SQL Server category; --> Sorry newbie question... I have made two different search queries on the same table that both retain the identical ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:42 PM
Alec
 
Posts: n/a
Default Joining SQL Results

Sorry newbie question...

I have made two different search queries on the same table that both
retain the identical column information.

$resultfirst = @mysql_query ("SELECT company, address1, address2 FROM
table1 WHERE category=active ")

$resultsecond = @mysql_query ("SELECT company, address1, address2 FROM
table1 WHERE category=inactive ")

How can I now join these together in one list, with the results from
the first query being listed before the second, ie keeping the same
order.

Many thanks

Alec Thorne

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:42 PM
Hugo Kornelis
 
Posts: n/a
Default Re: Joining SQL Results

On Mon, 08 Oct 2007 02:11:09 -0700, Alec wrote:

>Sorry newbie question...
>
>I have made two different search queries on the same table that both
>retain the identical column information.
>
>$resultfirst = @mysql_query ("SELECT company, address1, address2 FROM
>table1 WHERE category=active ")
>
>$resultsecond = @mysql_query ("SELECT company, address1, address2 FROM
>table1 WHERE category=inactive ")
>
>How can I now join these together in one list, with the results from
>the first query being listed before the second, ie keeping the same
>order.
>
>Many thanks
>
>Alec Thorne


Hi Alec,

SELECT company, address1, address2
FROM table1
WHERE category IN ('active','inactive')
ORDER BY category;

If category can only be active or inactive, you can omit the WHERE
clause. This is only required if other categories exist as well.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:42 PM
--CELKO--
 
Posts: n/a
Default Re: Joining SQL Results

>> How can I now join these together in one list, with the results from the first query being listed before the second, i.e. keeping the same order. <<

I hope these are the real names of the data elements.

SELECT category, company, address1, address2
FROM Table1
WHERE category IN ('active', 'inactive')
ORDER BY category, company, address1, address2;



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:43 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com