Tuesday, 13 January 2015

How data is retrieved from selected columns in SQL?

Fetch Data from Selected Columns

The SELECT command also allows you to retrieve data from specific columns. By specifying the desired column names, separated by commas, you can restrict your query to display the result you wish to see. In the example present below, you restrict data from three columns (department number, last name of employee, and manager number) from the Employees table. Note that the result of your query displays columns in the same order as you specified them in the SELECT statement. Also note that all the three columns are separated by commas.



NOTE
In Oracle, you can use the DESCRIBE command to list columns in a table. For example, to see a list of all columns in the Employees table, you’ll enter:

   DESCRIBE Employees

Use the following commands to get table definitions in other DBMSs:

  SQL Server:
  sp_help ‘employees’

  DB2:
   Describe table employees

  MySQL:
   Describe employees

  MariaDB:
   Show columns from employees;

  PostgreSQL:
   Id employees

  SQLite:
   Pragma table_info(employees);



    SQL Statement :
SELECT   department_id, last_name, manager_id
FROM          employees;

    Output :


Excerpt from the book: SQL - The Shortest Route For Beginners


No comments:

Post a Comment