USING

USING in SQL is a clause that is utilized in join statements, specifically for equi-joins, to specify columns on which the join should be performed. This clause helps in reducing redundancy when using joins by ensuring unique column names in the result set. It allows for more concise SQL queries.

Example

SELECT * FROM Employees;

Output

| ID | Name | Department |
|----|------|------------|
| 1 | Amy | HR |
| 2 | Ben | Finance |
| 3 | Carl | IT |

Explanation

In this SQL statement, SELECT * FROM Employees; is executed, which selects all the data from the Employees table. The ‘Output’ section shows the table displaying the result of the previous SQL statement. The table includes columns ‘ID’, ‘Name’, ‘Department’. The rows show the data of each employee in the ‘Employees’ table.

Example

CREATE TABLE Employees (
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50)
);
INSERT INTO Employees (ID,NAME,AGE,ADDRESS) VALUES (1, 'Tom', 25, '1234 Main St');
SELECT * FROM Employees;

Output

| ID | NAME | AGE | ADDRESS |
|----:|:----:|:---:|:-----------:|
| 1 | Tom | 25 | 1234 Main St|

Explanation

The SQL code defines a table ‘Employees’ and inserts a record into it. The output shows the resulting table as rendered in markdown, with one record for employee ‘Tom’.

Example

SELECT 'Hello, World!' AS Greeting FROM dual;

Output

GREETING
----------------
Hello, World!

Explanation

The SELECT statement retrieves values from the database. Here, a string ‘Hello, World!’ is selected and given the alias Greeting. The FROM clause indicates the table where the SQL statement will look for the data. In Oracle, Dual is a special one-row, one-column table present by default. The output is a single record with a single column named Greeting that contains the string ‘Hello, World!’.

Example

Markdown:

SELECT * FROM Employees WHERE Salary > 50000;

Output

Markdown:

Employee_IDFirst_NameLast_NameSalary
3JohnDoe60000
5JaneSmith75000

Explanation

The SELECT command is used to select data from a database. Here, it selects all the fields (*) from ‘Employees’ table where the ‘Salary’ field is greater than 50000. The result is a table that includes rows for ‘Employee_ID’, ‘First_Name’, ‘Last_Name’ and ‘Salary’ where the salary is more than 50000.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.