iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2005, 01:53 PM
WebProWorld Member
 
Join Date: Sep 2004
Location: Idaho
Posts: 40
MHenscheid RepRank 0
Default SQL Query Question

Let me start with a simplified example:

I have a database with fields "size", "color" and "sort_order_by_size"

short example of what the table might look like:

Size, Color, sort_order_by_size
S, Grey, 1
S, Blue, 2
S, Yellow, 3
M, Grey, 4
M, Yellow, 5

What I want to do is grab all "distinct" sizes and sort according to the sort_order_by_size field. I want my recordset to look like:

Size, sort_order_by_size
S, 1
M, 4

How do I write a query to get this result?
If I do: "Select distinct size from table", I do not get my sorting.
If I do: "Select distinct size, sort_order_by_size from table order by sort_order_by_size" the entire table is returned, since each value of sort_order_by_size is unique.

Any one have any suggestions?
Reply With Quote
  #2 (permalink)  
Old 02-18-2005, 05:58 PM
WebProWorld Member
 
Join Date: Nov 2004
Posts: 33
imported__sam_ RepRank 0
Default Re: SQL Query Question

Hello,

You did not explain why you want

Size, sort_order_by_size
S, 1
M, 4

and not e.g.

Size, sort_order_by_size
S, 3
M, 5

Nevertheless, what could work is this:

SELECT size, min(sort_order_by_size) FROM table GROUP BY size ORDER BY min(sort_order_by_size)

best regards

Sam
__________________
Software-Pointers.com - Directory of Software Development Sites - Free submission.
Reply With Quote
  #3 (permalink)  
Old 02-21-2005, 01:51 PM
WebProWorld Member
 
Join Date: Sep 2004
Location: Idaho
Posts: 40
MHenscheid RepRank 0
Default

Thanks for the reply! I will check it out.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:12 AM.



Search Engine Optimization by vBSEO 3.3.0