SQL Flashcards
Difference between where and on?
The ON clause defines the relationship between the tables.
The WHERE clause describes which rows you are interested in.
Many times you can swap them and still get the same result, however this is not always the case with a left outer join.
If the ON clause fails you still get a row with columns from the left table but with nulls in the columns from the right table.
If the WHERE clause fails you won’t get that row at all.
SELECT
SELECT distinct
SELECT CustomerName, City FROM Customers;
SELECT DISTINCT column1, column2, …
FROM table_name;
(select only distinct column1, and corresponding column 2 and other rows)
WHERE
SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2; WHERE condition1 OR condition2; WHERE NOT condition1
ORDER BY
SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … ASC|DESC;
- default will be ASC
- will order by column1, within same column1, will be order by column2
INSERT INTO
INSERT INTO table_name (column1, column2, column3, …)
VALUES (value1, value2, value3, …);
NULL VALUES
IS NULL
IS NOT NULL
can not be tested using =,
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
TODO
https://javarevisited.blogspot.com/2017/02/top-6-sql-query-interview-questions-and-answers.html
What is the difference between UNION and UNION ALL in SQL? (answer)
What is the difference between WHERE and HAVING clause in SQL? (answer)
What is difference between rank(), row_number(), and dense_rank() in SQL? (answer)
What is the difference between TRUNCATE and DELETE command in SQL? (answer)
How to compare date columns in SQL? (answer)
What is the difference between the Primary and Foreign key in SQL? (Answer)
What is the difference between view and materialized view? (answer)
Read more: https://javarevisited.blogspot.com/2017/02/top-6-sql-query-interview-questions-and-answers.html#ixzz6E96NF6Cn
https: //www.guru99.com/sql-interview-questions-answers.html
https: //www.javatpoint.com/sql-interview-questions