SQL Flashcards
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative programming language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results.
How do you retrieve specific columns from a database table?
select “columns” from table
How do you filter rows based on some specific criteria?
select “columns” from table where “rows”=’content’
What are the benefits of formatting your SQL?
easily readable
What are four comparison operators that can be used in a where clause?
=, < , >, !=
<>(not equal in postgresql)
How do you limit the number of rows returned in a result set?
limit clause and specify the number of rows
How do you retrieve all columns from a database table?
select * from table
How do you control the sort order of a result set?
select * from table order by “” desc
How do you add a row to a SQL table?
insert into table (columns)
values (values)
returning *;
What is a tuple?
a tuple is a finite ordered list of elements. (list of values)
How do you add multiple rows to a SQL table at once?
Data rows can be batch inserted into a database table by specifying more than one tuple of values, separated by commas.
How do you get back the row being inserted into a table without a separate select statement?
returning *;
How do you update rows in a database table?
update “table”
set “column”
Why is it important to include a where clause in your update statements?
to only target specific rows in the table
How do you delete rows from a database table?
delete from “table”
where “column”
How do you accidentally delete all rows from a table?
if you don’t target specific rows by including the ‘where’ clause
what is a foreign key?
A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables.
same column value
How do you join two SQL tables?
join table using column
How do you temporarily rename columns or tables in a SQL statement?
select columns as new-name (aliasing with the as keyword)
What are some examples of aggregate functions?
count, sum, max, min
What is the purpose of a group by clause?
want to separate rows into groups and perform aggregate functions on those groups of rows. This is done with a group by clause.