FROM: Understanding the FROM Clause in SQL

Learn SQL with Udemy

For an instructor lead, in-depth look at learning SQL click below.


Structured Query Language (SQL) is a standard programming language for managing data held in a relational database management system (RDBMS). It’s used to perform operations on the database such as inserting, deleting, updating and retrieving data. In this blog post, we will focus on one fundamental part of SQL, the FROM clause. The FROM clause is used to specify the tables where SQL should retrieve or manipulate data.

Basic use of the FROM Clause

In its basic form, the FROM clause is simply used to specify the table from which data should be selected. Here’s a simple example:

In this example, we’re selecting the ‘name’ and ‘age’ columns from the ‘Customers’ table.

Joining Tables with the FROM Clause

Apart from specifying the table to get data, the FROM clause is often used for joining multiple tables. Below is an example of how to join two tables ‘Orders’ and ‘Customers’ on the ‘customer_id’:

In this statement, we’re using an INNER JOIN operation to combine rows from ‘Customers’ and ‘Orders’ tables where the ‘customer_id’ matches.

Alias Using FROM Clause

The FROM clause is also used to set aliases for our tables, which can be especially useful when using JOIN operations on multiple tables. An example:

Here, we’ve set an alias for ‘Customers’ as ‘c’ and for ‘Orders’ as ‘o’. This helps us make our SQL statement more readable and tidy.

Conclusion

The power of SQL comes from its ability to interact with data directly where it resides, that is, in the database. The FROM clause is a vital part of SQL and mastering it can improve your efficiency in managing and working with your data. Keep practicing and soon you will master this essential SQL skill.


Leave a Comment