Logo
Pattern

Discover published sets by community

Explore tens of thousands of sets crafted by our community.

Database Joins and Subqueries

15

Flashcards

0/15

Still learning
StarStarStarStar

EQUI JOIN Example

StarStarStarStar

A join that retrieves records with equal values in the key columns defined with the ON clause. Example: SELECT * FROM table1 JOIN table2 ON table1.key = table2.key;

StarStarStarStar

RIGHT JOIN Example

StarStarStarStar

Used to return all records from the right table, and the matched records from the left table. Example: SELECT Orders.OrderID, Employees.LastName FROM Employees RIGHT JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID;

StarStarStarStar

FULL OUTER JOIN Example

StarStarStarStar

Used to return all records when there is a match in either left or right table. Example: SELECT Customers.CustomerName, Orders.OrderID FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;

StarStarStarStar

ALL Subquery Example

StarStarStarStar

Compares a value to every value returned by a subquery. Example: SELECT ProductName FROM Products WHERE ProductPrice > ALL (SELECT ProductPrice FROM Products WHERE ProductPrice > 10);

StarStarStarStar

Derived Table Subquery Example

StarStarStarStar

A subquery in a FROM clause creating a temporary table used in the outer query. Example: SELECT AVG(Price) FROM (SELECT Price FROM Products WHERE SupplierID = 2) AS SupplierPrices;

StarStarStarStar

Exists Subquery Example

StarStarStarStar

Used to test for the existence of any record in a subquery. Example: SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.SupplierId AND Price < 20);

StarStarStarStar

LEFT JOIN Example

StarStarStarStar

Used to return all records from the left table, and the matched records from the right table. Example: SELECT Customers.CustomerName, Orders.OrderID FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;

StarStarStarStar

CROSS JOIN Example

StarStarStarStar

Used to create a Cartesian product of rows from two or more tables. Example: SELECT Customers.CustomerName, Products.ProductName FROM Customers CROSS JOIN Products;

StarStarStarStar

INNER JOIN Example

StarStarStarStar

Used to select rows with matching values in both tables. Example: SELECT Orders.OrderID, Customers.CustomerName FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

StarStarStarStar

Correlated Subquery Example

StarStarStarStar

A subquery that depends on the outer query for its values. Example: SELECT e1.EmployeeName FROM Employees e1 WHERE EXISTS (SELECT * FROM Employees e2 WHERE e1.ManagerID = e2.EmployeeID);

StarStarStarStar

Uncorrelated Subquery Example

StarStarStarStar

A subquery that can be run independently of the outer query. Example: SELECT * FROM Employees WHERE EmployeeID IN (SELECT ManagerID FROM Employees);

StarStarStarStar

ANY/SOME Subquery Example

StarStarStarStar

Compares a value to each value returned by a subquery. Example: SELECT ProductName FROM Products WHERE ProductID = ANY (SELECT ProductID FROM OrderDetails WHERE Quantity > 100);

StarStarStarStar

NATURAL JOIN Example

StarStarStarStar

Implicitly joins tables based on columns with the same names. Example: SELECT * FROM table1 NATURAL JOIN table2;

StarStarStarStar

SELF JOIN Example

StarStarStarStar

Used to join a table to itself. Example: SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City FROM Customers A INNER JOIN Customers B ON A.CustomerID <> B.CustomerID WHERE A.City = B.City;

StarStarStarStar

Scalar Subquery Example

StarStarStarStar

A subquery that returns exactly one row and one column. Example: SELECT (SELECT COUNT(*) FROM Orders) AS TotalOrders;

Know
0
Still learning
Click to flip
Know
0
Logo

© Hypatia.Tech. 2024 All rights reserved.