Solved

Advanced Sql Select statement

Posted on 2007-11-18
3
1,015 Views
Last Modified: 2013-12-07
I have a database of 1.6 million products, all of them pertaining to a certain "category" that wasn't even set forth by me. Is there a specific statement I can do to get all the categories only once? For example, the results to be:
computers
art
electronics
software
NOT:
computers
computers
art
computers
software
software
0
Comment
Question by:jumpstart0321
3 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 20309933
group by category?
0
 
LVL 12

Accepted Solution

by:
RWrigley earned 500 total points
ID: 20309945
Use the "DISTINCT" clause on you select statement?

If you're database server is 2005, you could create an indexed view based on the category, and select form the view; this will not only give you just the distinct categories, but it'll also be much, much faster then scanning the 1.6million row table.
0
 

Author Comment

by:jumpstart0321
ID: 20310017
DISTINCT did it. Thanks :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

828 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