SQL terms Flashcards
GROUP BY
“How many times does the name of employees (N of times) appear on the table”
- results can be group according to specific field or fields (columns)
- if you only use GROUP BY clause you will only get distinct values for the column. like DISTINCT keyword (time efficency)
- in most cases, you will use use an aggregate function like COUNT(), SUM(),AVG(), MIN(), or MAX(), with an GROUP BY clause
- if you use COUNT() function, with GROUP BY clause, you will get a group of results of how many times each value appears on the table ( how time a names appears)
- Also, best practice, always include the field (“column”) you have grouped your results by in the SELECT statement. (“first_name”)
- placed after the WHERE clause
- placed before the ORDER BY clause
Syntax
- SELECT column_name(s) FROM table_name
WHERE conditions
GROUP BY column_name(s)
ORDER BY column_name(s);nswers this ty
COUNT() function -
- The COUNT() function returns the number of rows in a database table.
- this is a different than DISTINCT statement
The Asterisk * Symbol
- the wildcard asterisk symbol (*) represents the names of all the columns (field) in the table.
PRIMARY KEY
*Each table in sql has one unique primary key
- all the values on this column are unique, they cant be NULL VALUES
*a table can only have one primary key
Table
What is Database?
- database is a container that holds tables and other SQL structures realted to those tables.
- A database is an organized collection of data, stored and retrieved digitally from a remote or local computer system.
Definiton Query
you retrive, fetch data from database
Columns
defintion - is a piece of data stored by your table
- - columns also known as fields
- we read columns from top to bottom record
What is ROW
- definiton is a single set of columns that describe attributes of single thing.
- we also use record and row intercheangebily
WHERE vs HAVING
- when using aggragate functions use GROUP BY and HAVING
- general condition use - WHERE
interview question
What does GROUP BY do?
my personal definition
- the GROUP BY clause groups all the row values on specific column of a table that appear more than once into one group. for example. how many times does argentina appear on the country column of the able. By using the aggregate function COUNT() with GROUP BY, we can fetch a column on the workpace that shows the number of times argentina appears on the country column
Having Clause
- the HAVING clause was added because we cant use WHERE with aggregate functions
- frequently use with GROUP BY clause
- HAVING is like WHERE but applied to GROUP BY
WHERE clause
- Allows us to set conditions that refer to individual rows
- These conditon are applied before re-organizing the output into groups (using GROUP BY)
- use with general conditions
What is Primary Key
*Each table in sql has one unique primary key
* all the values on this column are unique, they can’t be NULL VALUES
What does SQL stand for?
- Structured Query Language
- It is the standard language for relational database management systems.
What is Database?
- A database is an organized collection of data, stored and retrieved digitally from a remote or local computer system.
- a database is collection of objects
What Are SQL constraints
specific rules, or limits, that we define in our table
What is a foreign key?
- points to the column of another table, thus it links two tables.
Relational Database
is a database where tables are related
Data Definition Language (DDL)
- group of SQL statements that you can execute to manage database objects. Such as tables, views and more.
- Sample Statements:
1. create, alter, drop, name, truncate - these set of statements allow users to define or modify data structures and objects. Exp. Tables