SQL For Data Scientist
SQL For Data Scientist
related. It includes:
1. Tables (or relations): Represented as rectangles, tables store data in rows and columns.
2. Columns (or attributes): Represented as vertical lines, columns define the data type and
constraints for each table.
3. Data Types: Define the type of data stored in each column (e.g., integer, string, date).
4. Relationships: Represented as lines connecting tables, relationships define how tables are linked
(e.g., one-to-one, one-to-many, many-to-many).
5. Primary Keys (PK): Unique identifiers for each table, ensuring data consistency and integrity.
6. Foreign Keys (FK): Columns that reference primary keys in other tables, establishing
relationships.
7. Indexes: Data structures that improve query performance by providing quick access to specific
data.
8. Constraints: Rules that enforce data consistency and integrity (e.g., NOT NULL, UNIQUE, CHECK).
NUMERIC is most common Float data type in sql which can store upto 38 digits float
VARCHAR is most common string data type in sql
< > means not equal to i.e. !=
SELECT (x/y) gives integer nearest integer answer if x and y are integers and float if x&y are float
i.e 2/10=0 and 2.0/10 =0.200000…
#Same applies for INTERSECT which retains common values only and EXCEPT which ignores
common values and retains other
21. Join with Subqueries (Nested Queries): SELECT * FROM TableName WHERE column IN (SELECT
column FROM AnotherTable WHERE condition);
22. Subquery in SELECT: SELECT col1, (SELECT col FROM Table2) AS col2 FROM Table1
23. Subquery in FROM:
We can add two tables in FROM clause where 2nd table is temporary view
SELECT col1, col2
FROM table1, table2
WHERE col1.table1=col1.table2 (a random condition)
#Inplace of table2 we can use (subquery) as in SELECT