SQL FROM Keyword



Purpose

The FROM keyword in SQL specifies the table from which you want to retrieve or modify data. It's essential in both SELECT (to get data) and DELETE (to remove data) statements.

Usage with SELECT

In a SELECT statement, FROM indicates the table to read data from. You can then specify which columns to retrieve.

Example 1: Selecting Specific Columns

This example selects the "CustomerName" and "City" columns from the "Customers" table.

SQL Query

SELECT CustomerName, City FROM Customers;
            
Output

-- Output will vary depending on your Customers table. Example:
-- CustomerName                      | City
-- ---------------------------------- | --------
-- Alfreds Futterkiste                | Berlin
-- Ana Trujillo Emparedados y helados | México D.F.
-- ...and so on...
            

Example 2: Selecting All Columns

To retrieve all columns from a table, use the asterisk (*) wildcard.

SQL Query

SELECT * FROM Customers;
            
Output

-- Output will show all columns and rows from the Customers table.
            

Usage with DELETE

In a DELETE statement, FROM specifies the table from which you want to delete rows.

Example 3: Deleting a Row

This example deletes a specific customer from the "Customers" table.

SQL Query

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';
            
Output

-- The output will typically indicate the number of rows affected (deleted).  For example:
-- (affected rows) = 1