SQL Flashcards

1
Q

Difference between where and on?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

SELECT

SELECT distinct

A

SELECT CustomerName, City FROM Customers;
SELECT DISTINCT column1, column2, …
FROM table_name;
(select only distinct column1, and corresponding column 2 and other rows)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

WHERE

A
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2;
WHERE condition1 OR condition2;
WHERE NOT condition1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ORDER BY

A

SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … ASC|DESC;

  1. default will be ASC
  2. will order by column1, within same column1, will be order by column2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

INSERT INTO

A

INSERT INTO table_name (column1, column2, column3, …)

VALUES (value1, value2, value3, …);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

NULL VALUES

A

IS NULL
IS NOT NULL
can not be tested using =,

SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TODO

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly