Unit 3 Database - Implementation - SQL SELECT Flashcards
What is SQL used for?
SQL is used to add, display, change, or delete data from a database.
What does a SQL statement consist of?
A SQL statement consists of instructions to interact with a database.
What does the SELECT statement do?
The SELECT statement retrieves and displays data from a table based on specified conditions.
What is the syntax for the SELECT clause?
SELECT * | column1, column2, … FROM table1, table2, …
What does the wildcard ‘’ mean in SQL?
The wildcard ‘’ means selecting all columns from a table.
How do you retrieve specific columns from a table?
Specify the column names after the SELECT keyword, e.g., SELECT userid, accountname FROM user;
What does ORDER BY do in SQL?
ORDER BY sorts the query results in ascending (ASC) or descending (DESC) order.
How do you retrieve all data from a single table?
Use SELECT * FROM table_name;
How do you retrieve a single column from a table?
Use SELECT column_name FROM table_name;
How do you retrieve two columns from a table?
Use SELECT column1, column2 FROM table_name;
What is an equi-join in SQL?
An equi-join is a join that matches rows based on equality between a primary key and a foreign key.
How do you perform an equi-join between two tables?
Use SELECT * FROM table1, table2 WHERE table1.primary_key = table2.foreign_key;
How do you retrieve data from two tables with a specific condition?
Use SELECT * FROM table1, table2 WHERE table1.primary_key = table2.foreign_key AND condition;
How do you use the ‘AND’ operator in SQL?
Use AND to ensure multiple conditions are met, e.g., WHERE column1 = value1 AND column2 = value2;
How do you use the ‘OR’ operator in SQL?
Use OR to allow either condition to be met, e.g., WHERE column1 = value1 OR column2 = value2;
How do you use both ‘AND’ and ‘OR’ in SQL?
Use parentheses to group OR conditions with AND, e.g., WHERE column1 = value1 AND (column2 = value2 OR column3 = value3);
How do you sort query results in descending order?
Use ORDER BY column_name DESC;
How do you sort query results in ascending order?
Use ORDER BY column_name ASC;
How do you retrieve specific rows based on multiple conditions?
Use WHERE with multiple conditions joined by AND or OR, e.g., WHERE column = value1 OR column = value2;
How do you retrieve specific columns from two tables?
Use SELECT table1.column1, table2.column2 FROM table1, table2 WHERE table1.primary_key = table2.foreign_key;
How do you order query results by multiple columns?
Use ORDER BY column1 DESC, column2 ASC;
How do you retrieve data for a specific client?
Use WHERE clientid = value;
How do you order results by multiple conditions in SQL?
Use ORDER BY column1 sorting_order, column2 sorting_order;