Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Advanced Sql Select statement

Posted on 2007-11-18
3
Medium Priority
?
1,020 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 2000 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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

916 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