Gaurav Soni
Gaurav Soni

Reputation: 6338

confusing query

Hi I have 3 table xyz abc and pqr,structure of xyz and abc is same ,but the query inside exists clause is confusing me ,why someone put the table pqr when there is no need of that ,even no joining is been done here with that table .

Insert into xyz 
select * from abc where exist (select 1 from pqr where abc.pk_id =1234)

abc.pk_id is primary key of table xyz

Note:I have not written this query this is existing in production ,please reply.

Upvotes: 1

Views: 72

Answers (2)

Vikram
Vikram

Reputation: 8333

there is no need for pqr table in this context the following query should do the same:

Insert into xyz 
select * from abc where pk_id =1234

Upvotes: 0

user359040
user359040

Reputation:

A slightly less confusing version of the same query might be:

Insert into xyz 
select * from abc where abc.pk_id = 1234 and exists (select 1 from pqr)

In other words, insert records from abc for the specified pk_id, when pqr is not empty.

Upvotes: 4

Related Questions