SQL With a Smile by Kellner Elaine

SQL With a Smile by Kellner Elaine

Author:Kellner, Elaine
Language: eng
Format: epub
Tags: SQL
Published: 2016-03-13T16:00:00+00:00


OrderDate

OrderID

DrinkID

2/5/2016

1

2

2/5/2016

1

5

2/5/2016

1

4

2/5/2016

1

3

2/5/2016

1

6

There’s a fix for that, though! If we want to see how many unique order IDs we have, we can use COUNT(DISTINCT) instead:

SELECT COUNT(DISTINCT OrderID) AS Order_Count

FROM DrinkOrders

Results:

Order_Count

1

There we go!

A word of caution - You can use COUNT(DISTINCT) even in those cases where you don’t have duplicate values. For example, using either COUNT(DrinkID) or COUNT(DISTINCT DrinkID) against our Menu table will both return the correct value of 5:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.