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] Table PAYMENTS with 1000 rows.
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.] Limit to 5 rows
โ˜‘๏ธ 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. Unique Amounts
โ˜‘๏ธ 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; Results for amount < 5.99

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Sukriti Macker

Sukriti Macker Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Sukriti_Macker

14 Jun
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
Read 5 tweets
9 Jun
Have you found the concepts of JOINS in SQL tricky? ๐Ÿ˜ตโ€๐Ÿ’ซ

A Beginner-Friendly JOINS guide that would help you in your SQL & Data Science Journey.

Thread ๐Ÿงต
โ˜‘๏ธ JOINS (Some Theory)
Using JOIN, we can query data from two or more tables based on the related column present in both tables.

While performing a join, we need to specify the shared column & the condition on which we want to join tables.
โ˜‘๏ธ Types of JOINS:-
1. Inner Join
2. Left Join
3. Right Join
4. Full Join
Read 14 tweets
7 Jun
Want to pursue Data Science? SQL is the most imperative skill required in it!

A Beginner's Guide to MySQL Queries part 4! ๐Ÿ“–
RETRIEVAL & LOADING the data!

Thread ๐Ÿงต
โœ… RETRIEVE THE DATA

The SELECT command allows the retrieval of information as per our requirements.

You can select/retrieve:-
1. All the data from the table using *
2. A single column
3. Multiple columns
1๏ธโƒฃ Select all columns of the table

SELECT * from table_name;

๐Ÿ‘‰ E.g., Selecting/Retrieving all the values from the classroom1 table.

2๏ธโƒฃ Select one column from the table

SELECT column_name from table_name;

๐Ÿ‘‰ E.g., Selecting the student_name column from the table classroom1. Retrieving ALL the columns ...Retrieving ONE column from ...
Read 5 tweets
6 Jun
SQL is the most wanted skill in Data Science!! ๐Ÿ˜ฑ

A Beginner's Guide to MySQL basic queries - Part 3!! ๐Ÿ˜Ž

Making mistakes while creating tables is common. Let's learn how to update and fix them! ๐Ÿ˜ฌ

Thread ๐Ÿงต
โœ… UPDATE THE TABLE

1. Add a column to the existing table:-

ALTER table table_name ADD (column_name datatype);

(Note: Adding a constraint to a column is optional)

๐Ÿ‘‰ E.g., Adding the ADDRESS column to the classroom1 table. Addition of a new column to the table classroom1
2. Add MULTIPLE columns at once:-

ALTER table table_name ADD (colname1 datatype1, colname2 datatype2);

๐Ÿ‘‰ E.g., Adding Email_id and ContactNo columns to the classroom1 table Adding multiple columns at once in classroom1 table.
Read 7 tweets
5 Jun
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.
Read 12 tweets
4 Jun
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.
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(