SQL Select Example


Select data from the student table in the Demo database

SQL Select *

USE Demo;
SELECT * FROM [DBO].[Student]

The * in the select statements means select all columns in the specified table. In the example above, the statement will select all the the columns in the students table.

Results: All rows and columns in the Student table will be selected.

SQL Select Specified Columns

When using the select statement in SQL, specific columns can be specified in the select statement.

USE Demo;
SELECT [ID]
      ,[First_Name]
      ,[Last_Name]
  FROM [DBO].[Student];

The statement above will select the ID, the First_Name, and the Last_Name columns from the Student table.

Results:

This image has an empty alt attribute; its file name is image-3.png
USE Demo;
SELECT [First_Name]
      ,[Last_name]
   FROM [DBO].[Student]

The statement above will only select the First_Name, and the Last_Name columns from the Student table.

SQL Select with WHERE

In SQL Select Statement, WHERE can be used to specify the records to be selected

USE Demo;
SELECT * FROM [DBO].[Student]
    WHERE ID = 1;

Results: The statement above will only select the student with the ID = 1




Thank you for visiting my blog. Please subscribe for more coding examples.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s