notes Flashcards
What is the goal of the lecture on SQL and Boolean Logic?
Understand Boolean Logic and SQL Querying, learn how logic gates, truth tables, and Venn diagrams apply to database queries, master SQL commands for data manipulation, querying, and management, and build a structured approach to writing SQL queries efficiently.
Who developed Boolean Logic?
George Boole (1815-1864) developed Boolean Logic.
What are the basic values in Boolean Logic?
True (1) and False (0).
What are the logical operators in Boolean Logic?
AND, OR, NOT.
What is a truth table?
A truth table helps evaluate logical expressions.
What does the AND operator do in SQL?
Both conditions must be true.
Example: SELECT * FROM employees WHERE department = ‘HR’ AND salary > 50000;
What does the OR operator do in SQL?
At least one condition must be true.
Example: SELECT * FROM employees WHERE department = ‘HR’ OR department = ‘IT’;
What does the NOT operator do in SQL?
Negates a condition.
Example: SELECT * FROM employees WHERE NOT department = ‘HR’;
How do Venn diagrams relate to SQL queries?
They represent intersection (AND, INNER JOIN), union (OR, UNION), and difference (NOT, MINUS).
What is SQL used for?
Defining database structures (DDL), manipulating data (DML), querying data (DQL), and controlling access (DCL).
What is the purpose of the SELECT statement in SQL?
The SELECT command retrieves data.
Example: SELECT first_name, last_name FROM employees;
How do you filter data in SQL?
Using the WHERE clause.
Example: SELECT * FROM employees WHERE salary > 60000;
How do you sort data in SQL?
Using the ORDER BY clause.
Example: SELECT * FROM employees ORDER BY salary DESC;
How do you remove duplicates in SQL?
Using the DISTINCT keyword.
Example: SELECT DISTINCT department FROM employees;
What is an INNER JOIN in SQL?
Returns matching records.
Example: SELECT orders.order_id, customers.customer_name FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id;
What is a LEFT JOIN in SQL?
Returns all from the left, matching from the right.
Example: SELECT customers.customer_name, orders.order_id FROM customers LEFT JOIN orders ON customers.customer_id = orders.customer_id;
What is the COUNT() function in SQL?
Counts rows.
Example: COUNT(*)
What is the SUM() function in SQL?
Adds values.
Example: SUM(salary)
What is the AVG() function in SQL?
Calculates average.
Example: AVG(salary)
What is the purpose of the INSERT statement?
Inserts data into a table.
Example: INSERT INTO employees (first_name, last_name, salary) VALUES (‘John’, ‘Doe’, 60000);
How do you update data in SQL?
Using the UPDATE statement.
Example: UPDATE employees SET salary = 70000 WHERE first_name = ‘John’;
How do you delete data in SQL?
Using the DELETE statement.
Example: DELETE FROM employees WHERE department = ‘HR’;