Home »
MySQL
MySQL FROM Clause
MySQL | FROM Clause: Learn about the MySQL FROM Clause, with its explanation, syntax, and query examples.
Submitted by Apurva Mathur, on September 09, 2022
FROM Clause
The FROM Clause helps us to select the data from some tables. As the name suggests, FROM Clause tells the machine from which table the data should be selected. It is one of the most used clauses in MYSQL; every other statement has FROM clause. We know that we have many tables in a single database and now from which table data should be fetched is dependent on this clause.
FROM Clause Syntax
SELECT column_name
FROM table_name;
Let us see some examples;
FROM Clause Examples
Case 1: Suppose we have a database named "new_schooldb" and inside this database, we have three tables;
Now, if I want to select all the details FROM a specific table named "student_details", in such case we will use the following query,
SELECT * FROM student_details;
Here * signifies all the details, and FROM signifies from which table the data should be fetched.
Case 2: Now, suppose we only want a few columns from this table, in such case, we will write,
SELECT student_name, Gender FROM student_details;
To get some specific columns from the table, it is important to separate them with commas.
Case 3: Suppose we only want to know the names of students of the "CSE" department, in such case, we will use the WHERE clause with FROM clause. WHERE clause is used to apply conditions, so here we will write,
SELECT * FROM student_details
WHERE student_department='CSE';
After hitting the query, it returned us the result which has all the details of the student from the "CSE" department.