VB.NET Select statement in SQL query

This article primarily devoted to the basics of SQL query, that is SELECT Statement: This SELECT statement is used to fetch data from the table.
  • 5037

This article primarily devoted to the basics of SQL query, that is SELECT Statement:

 

This SELECT statement is used to fetch data from the table.

Syntax:

SELECT column_name(s) FROM table_name

Suppose we have a "Employee" table

 

LastName

FirstName

Address

City

Singh

Bhupendr

10, K. Marg

New Delhi

Das

Bhasker

34, mall road

Kanpur

Singh

Ajeet

15, karol bagh

New Delhi

For Select Few Columns:


SELECT
LastName,FirstName FROM Employee

 Query Result is:



LastName                   FirstName

Singh                           Bhupendr

Das                              Bhasker

Singh                           Ajeet

 

Select All Columns

To select all columns from the "Employee" table, use a * symbol instead of column names, like this: 


SELECT
* FROM Employee

Query Result is:

 

LastName                  FirstName                  Address                               City

Singh                          Bhupendr                    10, K. Marg                           New Delhi

Das                            Bhasker                       34, mall road                        Kanpur

Singh                          Ajeet                           15, karol bagh                      New Delhi

 

The SELECT DISTINCT Statement

The DISTINCT keyword is used to fetch only distinct (different) values no repetitive values from the table.

Syntax

SELECT DISTINCT column_name(s) FROM table_name

 

Suppose we have one more table: "Orders" table

Company

OrderNumber

MCN

3412

Microsoft

2312

MCN

4678

Wipro

6798

 

Without using the DISTINCT keyword

To select ALL values from the column named "Company" we use a SELECT statement like this:

 

SELECT Company FROM Orders
 Query Result is:

 

Company

MCN

Microsoft

MCN

Wipro

 

To select only DIFFERENT values from the column named "Company" we use a SELECT DISTINCT statement like this:

 

SELECT DISTINCT Company FROM Orders
 Query Result is:

 

Company

MCN

Microsoft

Wipro

 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.