I'm trying to search some data in a table I don't have control over and I need to figure out how to do an logical and between two specified search items. I need to find all rows in a table that has the same value in collumn A and column B is equal to X or Y. The is similar to the following, but it contains more than 600,000 records.
Tablename: data_table
id
record_id
parm_type
value
0
0
1001
10
1
0
1002
20
2
0
1003
30
3
0
1004
40
4
1
1001
15
5
1
1002
25
6
1
1003
35
7
1
1004
45
8
2
1005
20
9
2
1002
30
10
2
1003
40
11
2
1008
50
12
3
1007
20
13
3
1002
30
14
3
1003
40
15
3
1007
50
16
4
1001
20
17
4
1002
30
18
4
1007
40
19
4
1008
50
I want to get every value with the same record_id, that has a parm_type type of 1002 or 1003 and the value is greater than 20 for type 1002 and less than 40 for 1003. Here is what I tried but it was taking very long and gets execution timeouts
SELECT id,record_id,parm_type,value FROM data_table
WHERE record_id IN
(
SELECT record_id FROM data_table
WHERE parm_type=1002 AND value > 20
)
AND record_id IN
(
SELECT record_id FROM data_table
WHERE parm_type=1003 AND value > 40
);
I know there have to be others ways to accomplish this, but I'm no DBA...
-Spacix All your