SQL Server > Query

Returning few columns only in SQL Server

How to return only few columns data from a SQL Server database table?

To return only few columns from a database table, we write column names followed by the SELECT statement.

In general, columns are written separated by comma however if the column name contains blank space, we warp them with square bracket “[column name].

SELECT FirstName, LastName, Age FROM PersonalDetails

SELECT [FirstName], [LastName], [Age] FROM PersonalDetails

Above, both query would return the same result. In 1st case directly field names are written and in 2nd case field names are wrapped with “[ ]”.

 Views: 10206 | Post Order: 43

Write for us

Hosting Recommendations