Lost your password? Please enter your email address. You will receive a link and will create a new password via email.


You must login to ask a question.

You must login to add post.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

RTSALL Latest Articles

Most commonly used SQL Queries | Part-2

Most commonly used SQL Queries | Part-2

SQL Queries, Today we see the most commonly used SQL queries in our daily developer’s life. If you are an SQL developer you must also go through these queries for revision purposes.

Define SELECT query or SELECT statement in SQL.

The SELECT statement is at the heart of most SQL queries. It defines what result set should be returned by the query, and is almost always used in conjunction with the FROM clause, which defines what part(s) of the database should be queried.

Using the wildcard character to SELECT all columns in a query:

Consider a database with the following two tables.

  1. Employee
IdFNameLNameDeptId
1JerrySmith3
2KamalSharma4
Employees table

2. Departments

IdName
1Sales
2Marketing
3Finance
4IT
Departments table:
Simple select statement

* is the wildcard character used to select all available columns in a table. When used as a substitute for explicit column names, it returns all columns in all tables that a query is selecting FROM. This effect applies to all tables the query accesses through its JOIN clauses.

Consider the following query:

SELECT * FROM Employees

It will return all fields of all rows of the Employees table:

IdFNameLNameDeptId
1JerrySmith3
2KamalSharma4
Employees table

Dot notation

To select all values from a specific table, the wildcard character can be applied to the table with dot notation.
Consider the following query:

SELECT
Employees.*,
Departments.Name
FROM
Employees
JOIN
Departments
ON Departments.Id = Employees.DeptId

This will return a data set with all fields on the Employee table, followed by just the Name field in the Departments
table:

IdFNameLNameDeptIdName
1JerrySmith3Finance
2KamalSharma4IT
Employees JOIN Departments Table

Also Read: Most commonly used SQL Queries | Part-1

Related Posts

Leave a comment

You must login to add a new comment.