Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Tutorial -> Sql Select

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 121
    Comment on it

    <-- Chapter 2: SQL Syntax

    Chapter 3

    SQL Select


    SQL Select : SELECT command describes that through which we can fetch data from MYSQL database tables OR we can say, It is used to retrieve/select data from MYSQL database.
    SELECT command is used for the purposes like fetch specific column fields, fetch all the column fields, we are going to learn all these purposes below.
    Let us learn the basic Syntax for SELECT command to retrieve all the column fields is :-


    SELECT * 
    FROM `tablename`;
    

    Here in the SQL statement the symbol (*) describes that all the columns fields are required. Lets go in depth. Suppose we have one table users in the database and we have designed the structure like this, first_name, last_name, age, designation, register_date,update_date. So here if we do :-


    SELECT * 
    FROM `users`;
    

    In the above sql statement we are fetching all the column fields from the table users. Lets organize this sql statement more , suppose in the web view page we want to display only user's first_name, last_name, age and designation. So now we will have to do a little bit change in the above sql statement. We will use the same SELECT command to retrieve these column fields. Lets see the sql statement below :-


    SELECT `first_name`,`last_name`,`age`,`designation` 
    FROM `users`;
    

    In the above sql statement we are now fetching particular column fields we need. In this tutorial we will see one example through which we can learn how the things going. Lets take an example for "employees" table . We have mysql database table structure below :-


    employee_id name code designation date
    101 ABC E-101 Engineer 21-12-2015
    102 DEF E-102 Doctor 18-09-2015
    103 GHI E-103 Software Developer 19-09-2015
    104 JKL E-104 CEO 10-09-2015
    105 MNO E-105 Software Developer 19-09-2015

    Now we will fetch specific columns here


    SELECT `employee_id`,`name`,`code` 
    FROM `employees`;
    

    Now Run this above query and you will see the output below :-


    employee_id name code
    101 ABC E-101
    102 DEF E-102
    103 GHI E-103
    104 JKL E-104
    105 MNO E-105

    Now we will fetch all (*) columns here


    SELECT *
    FROM `employees`;
    

    Now Run this above query and you will see the output below :-


    employee_id name code designation date
    101 ABC E-101 Engineer 21-12-2015
    102 DEF E-102 Doctor 18-09-2015
    103 GHI E-103 Software Developer 19-09-2015
    104 JKL E-104 CEO 10-09-2015
    105 MNO E-105 Software Developer 19-09-2015

    Chapter 4: SQL Distinct -->

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: