COUNT, DISTINCT, LIMIT

 The presenter discusses three useful expressions commonly used with SELECT statements in SQL:

  1. COUNT: COUNT is a built-in database function that retrieves the number of rows that match the query criteria. For example, to get the total number of rows in a table, you can use the query: SELECT COUNT(*) FROM tablename. If, for instance, you have a table named MEDALS with a column called COUNTRY and you want to know the number of rows where the medal recipient is from Canada, you can issue a query like this: SELECT COUNT(COUNTRY) FROM MEDALS WHERE COUNTRY='CANADA'.

  2. DISTINCT: DISTINCT is used to remove duplicate values from a result set. To retrieve unique values in a column, you can use the query: SELECT DISTINCT columnname FROM tablename. For example, in the MEDALS table mentioned earlier, you may want to retrieve the list of unique countries that received gold medals. This can be achieved by issuing a query like: SELECT DISTINCT COUNTRY FROM MEDALS WHERE MEDALTYPE = 'GOLD'.

  3. LIMIT: LIMIT is used for restricting the number of rows retrieved from the database. For example, to retrieve just the first 10 rows in a table, you can use the query: SELECT * FROM tablename LIMIT 10. This can be useful for examining a small subset of the result set without retrieving the entire set, which may be very large. For instance, to retrieve just a few rows in the MEDALS table for a particular year (e.g., 2018), you can issue a query like: SELECT * FROM MEDALS WHERE YEAR = 2018 LIMIT 5.

By understanding and utilizing these expressions, users can effectively manipulate and retrieve data from relational databases using SQL SELECT statements.

Comments

Popular posts from this blog

Lila's Journey to Becoming a Data Scientist: Her Working Approach on the First Task

Notes on Hiring for Data Science Teams

switch functions