Selecting specific columns

Selecting specific columns

In SQL database management systems, instead of using the * asterisk wildcard to select all table columns in an existing table, database users can preview specific column values ​​from an existing table by listing the column names in the SELECT SQL database command or statement that they want to display in the SQL database management software screen window.

Selecting specific columns

Syntax of a SQL SELECT statement.

SELECT column1, column2, column3 FROM table_name;

element of a SQL SELECT statement.

  • The SELECT command or statement is a reserved SQL keyword or command used to preview table data in an existing table.
  • Here, column1, column2, and column3 are the names of the columns in the existing table that the database user wants to display on the console screen. Database users can list and preview as many table columns as they want. Remember, each table column can be separated by a comma operator.
  • In this, the FROM statement specifies the name of the table from which the database user wishes to display or preview table column data.
  • Table_name is the name of the table in the database that the database user wishes to query for the column.

Example of a SELECT command or statement.

Suppose you have a database table named employe.

employee_id emp_name emp_age department salary

101 Siddhi deora 21 Marketing 74000

201 Harry deora 23 Development 44000

301 Bhavshi deora 37 Design 63000

Here, if the database user wishes to extract table data from an existing table containing only the emp_name and emp_age columns, the database user would write the SELECT statement as follows:

SELECT emp_name, emp_age FROM employe;

So, this SELECT query will display the table information like this:

emp_name emp_age

Siddhi deora 21

Harry deora 23

Bhavshi deora 37

Selecting multiple columns in an SQL database table.

Here, the database user can select and preview as many existing database table columns as they need. Here, multiple table column values ​​can be extracted and displayed by separating each table column name with a comma operator. For example, if the database user wants to select the emp_name, emp_age, and department column values ​​from the employe table, they can apply the following SELECT statement like this:

SELECT emp_name, emp_age, department FROM employe;

So, the above SELECT statement will display the query from the employe table like this:

emp_name emp_age department

Siddhi deora 21 Marketing

Harry deora 23 Development

Bhavshi deora 37 Design

Selecting specific table columns with conditions.

If database users want to filter data in an existing table, they can filter and display unique values ​​by adding a WHERE clause statement to select a particular table column. For example, if a database user wants to select and display the name and salary of employees over 32 years old in the EMPLOYEE table, they can use the following:

SELECT emp_name, salary FROM employe WHERE emp_age > 32;

This statement will preview the query results for this type of query.

emp_name salary

Bhavshi deora 63000

By selecting specific columns from a particular table in the Employee table, queries to the database table can be tailored to preview only the data results the database user wishes to preview. This can improve both database query performance and readability. This is especially useful in a production database environment, where database tables may have many columns selected, making it difficult to retrieve unnecessary table data.

Leave a Reply