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;

FROM Clause (Example 1)

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;
FROM Clause (Example 2)

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;
FROM Clause (Example 3)

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';
FROM Clause (Example 4)

After hitting the query, it returned us the result which has all the details of the student from the "CSE" department.

FROM Clause (Example 5)

ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.