mode 3 sql functionality Flashcards
What is a natural key?
it is a key that was obtained from outside of the
- database and is already unique
- > example: pokemon, SSN, license plate, username…
What is a Surrogate Key?
It is a key that was generated inside of the database itself.
What is a serial?
SERIAL is an integer
SERIAL keyword creates a new id in the table
What is a Composite Key?
two or more fields/ columns that create a unique value.
What is DQL?
Data Query Language
* SELECT statements is a part of DQL.
What is an alias?
its an alternate name,
alias allows you to give fields and tables another name the record set.
what is a record set?
It is the temporary table that you get back from a query
Different ways to use selects
SELECT * FROM employee;
–WHERE clause is a filter
SELECT * FROM employee WHERE title=’Sales Support Agent’;
– AND keyword only queries records if both conditions are met
SELECT * FROM employee WHERE title = ‘Sales Support Agent’ AND first_name = ‘Steve’;
– OR keyword queies records where only one of the conditions are met
SELECT * FROM employee WHERE first_name = ‘Andrew’ OR first_name = ‘Steve’;
–ALSO you can use >, =
SELECT * FROM employee WHERE reports_to >= (0+1);
How we use not equals on select
--is there not equals? /* * Ways to do not equals * - != * - <> * - NOT * */
How to do more generalized filters with strings?
- LIKE keyword, finds patterns and ATTRIBUTES
- —– ‘%’ is a wildcard that allows 0 or more characters
- —– ‘_’ is a wildcard that allows one specific character
How do we sort the data?
——
the keyword ORDER BY
Aggregate Functions
What is an aggregate function?
A calculation operating on a group of recrods/entriess, often producing 1 result;
Different types of aggregate functions
There are many different types of aggregate functions
- Examples:
- AVG: returns average on records
- MIN: minimum value
- MAX: max value
- SUM: sum of elements in the column
- DISTINCT:
What is the order of the WHERE, GROUP BY & HAVING keywords
order of the keywords matter, “WHERE” goes before “GROUP BY”
- goes before “HAVING”
- */
What is an aggregate function?
calculation on a set records to get generally a single value