Hello all,
Consider the following tables:
A: 1.000 records
B: 5.000.000+ records each referring to one A record
Pretty basic I think.
I have a query now that looks like this:
select A.c1, A.c2, A.c3
(select count(*) from B where B.id = A.idFromB
and B.c1 = somevalue and B.c2 = somevalue) computed1
from A
This query is performing rather badly because of the count(*). The only reason for using the count is to know IF there are records, not HOW MANY. So I wanted to change my count(*) into an exists, and there I am stuck.
I tried:
select A.c1, A.c2, A.c3
exists (select B.id from B where B.id = A.idFromB
and B.c1 = somevalue and B.c2 = somevalue) computed1
from A
select A.c1, A.c2, A.c3
if (exists (select B.id from B where B.id = A.idFromB
and B.c1 = somevalue and B.c2 = somevalue) true then 1 else 0 end computed1
from A
This all fails.
Is there a way to use exists in a subquery in the select clause? What other things could I consider to change the count(*) into something more performant?
Kind greetings,
Mim
Consider the following tables:
A: 1.000 records
B: 5.000.000+ records each referring to one A record
Pretty basic I think.
I have a query now that looks like this:
select A.c1, A.c2, A.c3
(select count(*) from B where B.id = A.idFromB
and B.c1 = somevalue and B.c2 = somevalue) computed1
from A
This query is performing rather badly because of the count(*). The only reason for using the count is to know IF there are records, not HOW MANY. So I wanted to change my count(*) into an exists, and there I am stuck.
I tried:
select A.c1, A.c2, A.c3
exists (select B.id from B where B.id = A.idFromB
and B.c1 = somevalue and B.c2 = somevalue) computed1
from A
select A.c1, A.c2, A.c3
if (exists (select B.id from B where B.id = A.idFromB
and B.c1 = somevalue and B.c2 = somevalue) true then 1 else 0 end computed1
from A
This all fails.
Is there a way to use exists in a subquery in the select clause? What other things could I consider to change the count(*) into something more performant?
Kind greetings,
Mim