Viewers: in countries Watching now:
In SQL Server 2008 Essential Training, Simon Allardice explores all the major features of SQL Server 2008 R2, beginning with core concepts: installing, planning, and building a first database. Explore how Transact-SQL is used to retrieve, update, and insert information, and gain insight into how to effectively administer databases. The course also covers features outside SQL Server's database engine, including technologies that have grown up around it: SQL Server Reporting Services and Integration Services. Exercise files are included with the course.
Okay, next up is a fairly easy one. Let's say I have got a straightforward SQL statement here, just selecting star from SalesLT.Address, and I scan some of this information and see that I've got a lot of information such as different states and different countries and regions. And what I might be interested in this is this. I don't really care about the individual pieces of data, but I'd like to know, for example, what the different countries are that we ship to. Well, I could start off by just filtering this data down.
Rather than SELECT *, I'll just say well, SELECT CountryRegion FROM SalesLT.Address and execute that. It still returns 450 rows that I could scan through, and it certainly doesn't look like there are too many countries, but just to be sure how could I start to ask for those individual values. I really just want to know it is Canada, the US, and whatever counties there are. Well, this is what I do. I use the word DISTINCT in the SELECT statement just before the actual column that I'm interested in, which really means only bring me back an individual value, just bring it back once for each value, even if it's repeated. I execute that.
We get now the distinct values for this column, which is Canada, United Kingdom, and United States. Now, if you find it useful, you can even go a little deeper than that. If I, for example, wanted to find both the distinct country regions and within that, we're actually storing StateProvince too. That's one of the columns in this table. I don't need to use the word DISTINCT again, but if I execute this line, what I'll get is the distinct countries and the distinct state provinces, whether they're repeated or not.
DISTINCT can be a very useful keyword when you find yourself getting too much data back and you really just want to filter it down, and in fact you'll find that using this DISTINCT keyword can actually be very useful even if you feed it into one of the other functions. For example, I could surround that phrase with the COUNT function, execute that, and I just get the answer. How many countries do we ship to? Three. I'm counting the distinct ones and just totaling them up.
Find answers to the most frequently asked questions about SQL Server 2008 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.