narhari
narhari

Reputation: 21

Select columns without using subquery in mysql

I want to select some records from table "A" but records that are not in table "B".

Example... Tables are...

A{A_ID, A_Date, A_Price};

B{B_ID, A_ID};

I want to select records from table "A" with primary key A_ID but only those records that are not table "B" on joining both table on primary key A_ID. I can do this with query...

select * from A where A_ID not in (select A_ID from B)

but my problem is subquery. Because it takes too much time run, if data quantity big.

SO I WANT TO RUN IT WITHOUT SUBQUERY.

please help!!!

Upvotes: 0

Views: 168

Answers (1)

Michał Turczyn
Michał Turczyn

Reputation: 37367

Try these queries:

select * from TableA A
where not exists(select 1 from TableB where A_ID = A.A_ID)

or

select A.* from TableA A left join TableB B
on A.A_ID = B.A_ID
where B.B_ID is null

Upvotes: 1

Related Questions