Karla News

Display Table Information by SQL

Sql

By using the “CREATE TABLE” command you can create a table in SQL. What if you want to see the contents of table? In SQL you can see the contents of your table using the command “SELECT”. Using select command you can see the data of your table in four formats:

1. All rows, all columns

2. All rows, selected columns

3. Selected rows, selected columns

4. Selected rows, all columns

ALL ROWS AND ALL COLUMNS:

In order to view all the rows and columns of your table. The syntax is:

Select to from ;

Here column 1 to column n is used to represent all the columns. Example: if you want to see all the rows and all the column of table student with column name “name”, “fees”, “marks”, “percentage”.

Select name, fees, marks, percentage from student;

Or; you can use “*” in spite of specifying all the column names like:

Select * from student;

To filter the data from the table i.e. to select some useful data from table you can use any of the below syntax:

ALL ROWS AND SELECTED COLUMNS:

To view specific column from the table this syntax is followed:

Select , from ;

Here column name 1 and column name 2 is used to represent the required column from your table. Example: if you want to see the name and percentage of student table than it will be done by:

Select name, percentage from student;

This will list all the rows but select columns like name and percentage.

SELECTED ROWS AND SELECTED COLUMNS:

See also  Apple Macbook Tutorial: How to Connect to a Vizio HDTV

To view or retrieve the selected rows and selected columns from your table the syntax followed is:

Select , from where ;

Till now you have list all the rows but if you want to filter rows based on some condition than it can be done in SQL by a clause “where”. Where clause is used to specify some condition and the oracle engine compares each record in the table with the condition. This will select some specified columns and selected rows which will satisfy the condition followed by “where”. Example: if you want to see name, marks and percentage of the student whose name starts with “a” than it will be done by:

Select name, marks, percentage from student where name like ‘a%’;

This command will list name, marks, percentage of those students whose name starts with ‘a’.

SELECTED ROWS AND ALL COLUMNS:

You want to retrieve or list the entire column but on some specified condition than the syntax followed are:

Select * from where ;

This will list all the column with the rows which will satisfies the condition followed by where clause. Example: if you want to retrieve the entire column with the condition that lists only those students who scores percentage above 80%. The syntax is:

Select * from student where percentage>80;

This will lists the entire column with the percentage above 80%.

Reference: