Consider a database with the following two tables.

Employees table:

Id | FName | LName | DeptId | —— | —– | —– | —— | 1 | James | Smith | 3 | 2 | John | Johnson | 4 |

Departments table:

Id | Name | —— | —– | 1 | Sales | 2 | Marketing | 3 | Finance | 4 | IT |

Simple select statement

\\* is the wildcard character used to select all available columns in a table.

When used as a substitute for explicit column names, it returns all columns in all tables that a query is selecting FROM. This effect applies to all tables the query accesses through its JOIN clauses.

Consider the following query:

SELECT * FROM Employees

It will return all fields of all rows of the Employees table:

Id | FName | LName | DeptId | —— | —– | —– | —— | 1 | James | Smith | 3 | 2 | John | Johnson | 4 |


Dot notation

To select all values from a specific table, the wildcard character can be applied to the table with dot notation.

Consider the following query:

SELECT 
    Employees.*, 
    Departments.Name
FROM 
    Employees
JOIN 
    Departments 
    ON Departments.Id = Employees.DeptId

This will return a data set with all fields on the Employee table, followed by just the Name field in the Departments table:

Id | FName | LName | DeptId | Name | —— | —– | —– | —— | —– | 1 | James | Smith | 3 | Finance | 2 | John | Johnson | 4 | IT |

Warnings Against Use