The FROM clause can generally be anything that returns a rowset, a TABLE, VIEW, function, or system-provided information like the Information Schema. The FROM clause can also include optional JOIN subclauses and sub-queries to specify the rules for joining tables.
SELECTING from multiple tables
You can include multiple tables in the FROM clause by listing the tables with a comma in between each table name:
This will select all rows from the user_list, member_type, message_list tables where the user_name is 'john'.
Using ALIASES with tables names
A table or column can be given a "shorthand" name by using an ALIAS. This can be helpful if the SQL statement is complex or the table or column names are long.
Lets say we have a table called "user_list" and another table called "member_type". We want to get data from both tables for the name 'John Smith'. First we'll write the query without using aliases:
SELECT member_type.user_info, user_list.last_name, user_list.first_name
Now we'll write the same SQL, but to make it easier to write our SQL statement, we'll give the user_list table an alias of "U" and the member_type table an alias "M":
SELECT M.user_info, U.last_name, U.first_name
As you can see, the SQL statement with aliases is more compact and easier to write.
Related Code Snippets:
|© 2003 - 2024 psoug.org