sql select Flashcards
What is SQL and how is it different from languages like JavaScript?
Structured Query Language is a way of interacting with relational databases to retrieve, create and manipulate data. SQL is a declarative programming language, programmers describe the result like HTML and CSS.
How do you retrieve specific columns from a database table?
select “string”, “string” from “table to retrieve from”;
to select all use select * from “products”
column double quotes
How do you filter rows based on some specific criteria?
using the where clause.
where double quotes comparison operator single quote
select “productID”, “name”, “price”
from “products”
where “category” = ‘cleaning’;
What are the benefits of formatting your SQL?
makes it easier to read and access data
What are four comparison operators that can be used in a where clause?
=
!=
<
>
How do you limit the number of rows returned in a result set?
with the Limit clause
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
order by “price” desc (descending)
limit 1;
How do you add a row to a SQL table?
insert statement
insert into “ “ ( “ “ )
values ( ‘ ‘ ) ;
What is a tuple?
A list of values
How do you add multiple rows to a SQL table at once?
specify more than one tuple of values separated by commas:
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
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 clause:
update “products”
set “price” = 200,
“name” = ‘Super ShakeWeight’,
“description” = ‘Makes you ULTRA strong!’
where “productId” = 24;
Why is it important to include a where clause in your update statements?
otherwise all of the rows will update
How do you delete rows from a database table?
delete clause
delete from “products”
where “category” = ‘cleaning’
and “price” < 20
returning *;