Home » SQL

SQL USING Clause

SQL | USING Clause: In this tutorial, we are going to learn about the USING clause with its usages, syntax and query examples in SQL (Structured Query Language).
Submitted by Abhishek Goel, on April 05, 2020

SQL | USING Clause

On the off chance that few sections have similar names however the datatypes don't coordinate, the NATURAL JOIN statement can be altered with the USING condition to determine the segments that ought to be utilized for an EQUIJOIN.

  • USING Clause is utilized to coordinate just a single section when more than one segment matches.
  • Regular JOIN and USING Clause are unrelated.
  • It ought not to have a qualifier(table name or Alias) in the referenced segments.
  • Regular JOIN utilizes all the segments with coordinating names and datatypes to join the tables. The USING Clause can be utilized to determine just those segments that ought to be utilized for an EQUIJOIN.

Syntax:

    SELECT <table_name>.<column_name> AS <column_name> 
    FROM <table_name> JOIN <table_name> USING (<column_name>);

Example:

Here we will be considering the following two tables,

Table: PETS

PETIDANIMALNAMEOWNERID
11DogRocky23
22CatCharles34
33MouseMickey23
44ParrotHoney56
55RabbitSmudge34
66HamsterFluffy56

Table: Owner

OWNERIDNAME
23Tina
34Tarun
56Sammy

Query: To Know the names of the owners of the pet.

SELECT Owner.name AS owners, PETS.name AS pet, PETS.Animal 
FROM Owner JOIN PETS USING (ownerid);

Output:

OWNERSPETANIMAL
TinaRockyDog
TarunCharlesCat
TinaMickeyMouse
SammyHoneyParrot
TarunSmudgeRabbit
SammyFluffyHamster

Note: At the point when we utilize the USING proviso in a join explanation, the join section isn't qualified with table Alias. Don't Alias it regardless of whether a similar segment is utilized somewhere else in the SQL explanation.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.