04 - Basic SQL Statements Flashcards

1
Q

Basic SELECT statement?

A

SELECT [field list]

FROM [tableName];

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

Basic WHERE clause?

A

SELECT [field list]

FROM [tableName]

WHERE [condition list];

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

Explain the following Boolean characters:

  • <
  • >
  • <=
  • >=
  • <>
A
  • < : smaller than
  • > : largern than
  • <= : smaller or equal
  • >= : equal or larger
  • <> : not equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain DISTINCT function?

A

SELECT DISTINCT(Division) From Personnel;

Shows different values of given columns.

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

ORDER BY statement?

A

SELECT [field list]
FROM [tableName]
ORDER BY [field] [ASC|DESC];

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

GROUP BY statement?

A

SELECT [field]
FROM [tableName]
GROUP BY [field];

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

Forensic functions?

A

SELECT Name, MD5(Name) FROM Personnel;
SELECT Name, SHA1(Name) FROM Personnel;

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

Regular Expression Matching - Find any name in Personnel beginning with “Jo”?

A

SELECT *
FROM [tableName]
WHERE Name REGEXP “^Jo”;

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

DELETE Command?

A

DELETE FROM [table]
[WHERE [condition]];

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

UPDATE Command?

A

UPDATE [table]
SET [field] = [value];

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

DESCRIBE Command?

A

DESCRIBE [tableName];

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

ALTER TABLE Command?

A

ALTER TABLE [tableName]
ADD INDEX [indexName] [indexfieldName]
| ADD PRIMARY KEY ([fieldName])
| ADD COLUMN ([fieldName])
| DROP PRIMARY KEY
| DROP INDEX
| DROP COLUMN [fieldName]

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

Check for NULL values?

A

SELECT [fields]
FROM [tableName]
WHERE [field] IS NULL;

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

Regular JOIN statement?

A

SELECT Personnel.Name, Cases.Type
FROM Personnel, Cases
WHERE Personnel.PID = Cases.OIC;

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

INNER JOIN statement?

A

SELECT Personnel.Name, Cases.Type
FROM Personnel
INNER JOIN Cases ON
Personnel.PID = Cases.OIC;

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

LEFT JOIN statement?

A

SELECT Personnel.Name, Cases.Type
FROM Personnel
LEFT JOIN Cases ON
Personnel.PID = Cases.OIC;

17
Q

How do you use the BETWEEN statement?

A

SELECT

InvoiceId,

BillingAddress,

Total

FROM

invoices

WHERE

Total BETWEEN 14.91 and 18.86

ORDER BY

Total;