Let's dive further into SQL to help you through the most demanding skill required in the Data Science Industry.
A Beginner's Guide to Filter Results in MySQL - Part 5!!
Thread ๐งต
โ๏ธ LIMIT Clause
To restrict the number of rows in the final result, we use the LIMIT clause.
That means if you have 10,000 rows in the data, you can fetch only 10 rows using this clause in your query.
๐ Query: select * table_name LIMIT limit_no;
For e.g., Consider a table PAYMENTS. It has more than 1000 rows. [See the image]
To fetch only 5 rows from the PAYMENTS table, we write a query as follows:-
Query: select * from payments limit 5;
[We get the result as shown in the image.]
โ๏ธ DISTINCT Clause
This clause is used to filter out results based on unique values, i.e., the distinct clause is used to get UNIQUE results only.
๐ Query: select DISTINCT column_name from table_name;
Considering the same PAYMENTS table, we use the DISTINCT clause to find all the unique AMOUNTs.
Query: select DISTINCT amount from payments;
Despite 1000 records, the distinct (unique) amount values are only 19.
โ๏ธ WHERE Clause
Using this clause, we can specify selection criteria to select the required records from the table.
It works like an IF CONDITION.
You can specify conditions using:- 1. Relational Operators (>,<,=) 2. Logical Op (AND, OR) 3. IS NULL or IS NOT NULL
Example:-
Selecting records where the amount is less than 5.99.
๐ Query: select * from payment where amount < 5.99;
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh
Hey, folks! Some time back, I was scrolling through LinkedIn and found some essential SQL topics to revisit before an Interview.
Have a look ๐งต๐
1. WHERE, AND, OR, NOT, IN 2. ORDER BY, ASC, DESC 3. IS NULL 4. LIMIT 5. MIN, MAX, COUNT, AVG, SUM 6. LIKE, WILDCARDS 7. IN BETWEEN 8. INNER JOIN 9. LEFT JOIN
10. UNION ALL 11. GROUP BY 12. HAVING 13. LEFT, RIGHT, MID, CONCAT 14. PARTITION BY, OVER 15. LEAD, LAG 16. Subqueries 17. RANK, DENSE_RANK, PERCENT_RANK 18. ROW_NUMBER, CUME_DIST 19. FIRST_VALUE, LAST_VALUE 20. AS
Basic Queries MySQL part 2 (Let's fill the table up!) ๐
Beginner Friendly!
Thread ๐งต
โ What are the keys in a relational database?
Keys help you uniquely identify a row in the table. It is also used to create relationship amongst various tables in a database.
The major types of keys:-
Primary Key
Candidate Key
Super Key
Foreign Key
Super Key: A set of one or more attributes or columns that identify a row/record in the table. It may consist of some columns that are not needed for the unique identification of a row.
SQL is a crucial skill for a Data Scientist! I would be releasing everything I know, little by little, and then a compiled version of all the threads you could revisit.
A Beginner's Guide to MySQL basic queries ๐ -Part 1 (Creation of Everything!)
Thread ๐งต
What is a database?
An organised collection of data that can be interrelated & makes operations like retrieval, insertion & deletion of data efficient.
User can perform different queries to perform an action based on their requirements.
Types:-
Hierarchical
Network
OO Database
A relational database is a type of database that stores everything in relations or tables.
Tables have columns and rows.
SQL -> Structured Query Language used to interact with a relational database.