SQL

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

flashcard set

Earn XP

Description and Tags

Queries

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

Subqueries

A Subquery is a SQL query embedded within the WHERE clause of another SQL query

SELECT employee_id, first_name, last_name, job_id
FROM employees
WHERE department_id IN (
    SELECT department_id
    FROM departments
    WHERE location_id IN (
        SELECT location_id
        FROM locations
        WHERE city = 'Seattle'
    )
)
ORDER BY employee_id 

Here there are 2 subqueries.

location_id is common between tables locations and departments
department_id is common between tables employees and departments

2
New cards

WHERE

knowt flashcard image
3
New cards

BETWEEN

Between is inclusive of the upper & lower limit of the range specified.

<p><span>Between is inclusive of the upper &amp; lower limit of the range specified.</span></p>
4
New cards

IN

knowt flashcard image
5
New cards

WHERE & LIKE

  • WHERE clause is used for filtering of records.

<ul><li><p><span>WHERE clause is used for filtering of records.</span></p></li></ul><p></p>
6
New cards

IS NULL

The absence of any value in a cell is represented by the NULL keyword.

<p><span>The absence of any value in a cell is represented by the <strong>NULL </strong>keyword.</span></p>
7
New cards

TRIM() function

removes excess spaces from the beginning or end of a string value

<p><span><strong>removes excess spaces from the beginning or end of a string value</strong></span></p>
8
New cards

IFNULL() function

 check for null values in a column and if found, replace them with some other value.

SELECT employeeNumber,firstName,lastName,
IFNULL(email,"N/A") AS email,
IFNULL(phone,"N/A") AS phone
FROM employees

in email column if there are any null values it will be replaced by N/A and again show the column email

9
New cards

CASE statement

What if you want to take some action based on a certain condition?

<p><span>What if you want to take some action based on a certain condition?</span></p>
10
New cards

IF() function

IF(condition, true_value, false_value)

<p><span>IF(condition, true_value, false_value)</span></p>
11
New cards

Wildcards

 partially matched strings using a comparison operator called LIKE, and wildcard characters, which serve as a placeholder for unknown characters in a string.

<p><span>&nbsp;<strong>partially matched strings</strong> using a <strong>comparison operator </strong>called<strong> LIKE</strong>, and <strong>wildcard characters</strong>, which serve as a placeholder for unknown characters in a string.</span></p>
12
New cards

SUBSTR().

Syntax: SUBSTR(value, position, length)

position tells us which character to start from.

length tells us up to which character we should include.

<p><span><strong>Syntax: </strong>SUBSTR(value, position, length)</span></p><p><span><strong>position</strong> tells us which character to start from.</span></p><p><span><strong>length</strong> tells us up to which character we should include.</span></p>
13
New cards

OFFSET

omit a specified number of rows before the beginning of the result set

<p><span><strong>omit a specified number of rows before the beginning</strong> of the result set</span></p>
14
New cards

ROUND() function.

The ROUND() function can also accept negative numbers for the second parameter, to round digits that are to the left of the decimal point

For example, SELECT ROUND(1245, -2) will return a value of 1200.

<p><span>The ROUND() function can also accept negative numbers for the second parameter, to <strong>round digits that are to the left of the decimal point</strong>.&nbsp;</span></p><p><span>For example, SELECT ROUND(1245, -2) will return a value of 1200.</span></p>
15
New cards

CEIL,FLOOR

CEIL(5.4) -> 6
FLOOR (5.7) -> 5