DML: Data Manipulation Language
In the earlier sessions, we have seen how to INSERT data into a table and How to UPDATE data in the table.
The main purpose of the database is to store and retrieve date.
Once data is inserted/updated ( stored ) in the database, then our next goal is to fetch(retrieve) the data which we stored earlier.
In this article we will see simple SELECT command . SELECT Command can go with many other command like WHERE, GROUP BY, HAVING, ORDER BY, TOP, DISTINCT, COUNT etc., I will explain in detail about all these commands in coming session. For now, lets limit this session to a simple SELECT Command.
Here is the Simple SELECT Command Syntax in SQL SERVER.
Syntax:
Assume that we have a table (MYPASSWORDS) with the following information. This table contains list of my email ids and corresponding passwords.
Execute the command given in Syntax 1: (SELECT * FROM MYPASSWORDS) . Result set for this query is given below:
Execute the command given in Syntax 2: (SELECT ACCOUNID,PWD FROM MYPASSWORDS) . Result set for this query is given below. This will fetch only Account Id and password from the table.
Summary:
This article describes how to use SELECT command for simple data retrieval.
In the earlier sessions, we have seen how to INSERT data into a table and How to UPDATE data in the table.
The main purpose of the database is to store and retrieve date.
Once data is inserted/updated ( stored ) in the database, then our next goal is to fetch(retrieve) the data which we stored earlier.
In this article we will see simple SELECT command . SELECT Command can go with many other command like WHERE, GROUP BY, HAVING, ORDER BY, TOP, DISTINCT, COUNT etc., I will explain in detail about all these commands in coming session. For now, lets limit this session to a simple SELECT Command.
Here is the Simple SELECT Command Syntax in SQL SERVER.
Syntax:
- SELECT * FROM <Table Name> : This command retrieves complete data from the table (i.e, information from all the columns).
- SELECT Col1, Col2,Col3,....ColN FROM <Table Name>: This command retrieves the data from only the columns which are used in the select command.
Assume that we have a table (MYPASSWORDS) with the following information. This table contains list of my email ids and corresponding passwords.
ACCOUNT | ACCOUNTID | PWD |
GMAIL | catchme@gmail.com | asderuom09 |
GMAIL | sqldeveloper@gmail.com | sqlpor739 |
GMAIL | sqldeveloper@gmail.com | sqlpor739 |
YAHOL | myyahooid@yahoo.com | olju67 |
YAHOL | sqlmyid@yahoo.com | itryry67 |
Execute the command given in Syntax 1: (SELECT * FROM MYPASSWORDS) . Result set for this query is given below:
Execute the command given in Syntax 2: (SELECT ACCOUNID,PWD FROM MYPASSWORDS) . Result set for this query is given below. This will fetch only Account Id and password from the table.
Summary:
This article describes how to use SELECT command for simple data retrieval.