Click here to Skip to main content
15,897,371 members
Home / Discussions / Database
   

Database

 
AnswerRe: Sql Joines Pin
Abhijit Jana7-Aug-09 21:31
professionalAbhijit Jana7-Aug-09 21:31 
GeneralHiring home based workers (3171) Pin
texzeb7-Aug-09 4:18
texzeb7-Aug-09 4:18 
RantRe: Hiring home based workers (3171) Pin
Ashfield7-Aug-09 9:36
Ashfield7-Aug-09 9:36 
Questionora-12528 tns listener all appropriate instances are blocking new connections Pin
vikash_singh7-Aug-09 2:35
vikash_singh7-Aug-09 2:35 
AnswerRe: ora-12528 tns listener all appropriate instances are blocking new connections Pin
Vimalsoft(Pty) Ltd7-Aug-09 3:32
professionalVimalsoft(Pty) Ltd7-Aug-09 3:32 
QuestionReporting Service - Administrator accounts Pin
devvvy7-Aug-09 1:37
devvvy7-Aug-09 1:37 
QuestionDebugging Postgresql plpgsql [modified] Pin
Jacobus016-Aug-09 23:38
Jacobus016-Aug-09 23:38 
QuestionHelp with optimization for searching a data table for a logical 'AND' Pin
Spacix One6-Aug-09 18:03
Spacix One6-Aug-09 18:03 
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
41 100115
51 100225
61 100335
71 100445
82 100520
92 100230
10 2 1003 40
11 2 1008 50
123 100720
133 100230
14 3 1003 40
15 3 1007 50
164 100120
174 100230
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 skynet questions[^] belong to solved

AnswerRe: Help with optimization for searching a data table for a logical 'AND' Pin
N a v a n e e t h6-Aug-09 19:07
N a v a n e e t h6-Aug-09 19:07 
GeneralRe: Help with optimization for searching a data table for a logical 'AND' Pin
Spacix One7-Aug-09 2:32
Spacix One7-Aug-09 2:32 
AnswerRe: Help with optimization for searching a data table for a logical 'AND' Pin
i.j.russell6-Aug-09 21:33
i.j.russell6-Aug-09 21:33 
GeneralRe: Help with optimization for searching a data table for a logical 'AND' Pin
Spacix One7-Aug-09 2:36
Spacix One7-Aug-09 2:36 
QuestionRe: Help with optimization for searching a data table for a logical 'AND' Pin
Spacix One7-Aug-09 2:24
Spacix One7-Aug-09 2:24 
AnswerRe: Help with optimization for searching a data table for a logical 'AND' Pin
David Skelly7-Aug-09 2:37
David Skelly7-Aug-09 2:37 
GeneralRe: Help with optimization for searching a data table for a logical 'AND' Pin
Spacix One7-Aug-09 2:49
Spacix One7-Aug-09 2:49 
NewsRe: Help with optimization for searching a data table for a logical 'AND' Pin
Spacix One7-Aug-09 3:07
Spacix One7-Aug-09 3:07 
QuestionQuery a DB for a field value on SQL 2005 STD SP2 Pin
Hulicat6-Aug-09 7:43
Hulicat6-Aug-09 7:43 
AnswerRe: Query a DB for a field value on SQL 2005 STD SP2 Pin
David Mujica6-Aug-09 8:06
David Mujica6-Aug-09 8:06 
GeneralRe: Query a DB for a field value on SQL 2005 STD SP2 Pin
Hulicat6-Aug-09 8:22
Hulicat6-Aug-09 8:22 
Questionproblem with creating view? Pin
shankbond6-Aug-09 2:45
shankbond6-Aug-09 2:45 
AnswerRe: problem with creating view? Pin
Ashfield6-Aug-09 8:57
Ashfield6-Aug-09 8:57 
Questionhow to check " is not null condition" in a field of single select query Pin
anushh6-Aug-09 0:45
anushh6-Aug-09 0:45 
AnswerRe: how to check " is not null condition" in a field of single select query Pin
WoutL6-Aug-09 1:21
WoutL6-Aug-09 1:21 
GeneralRe: how to check " is not null condition" in a field of single select query Pin
anushh6-Aug-09 2:24
anushh6-Aug-09 2:24 
GeneralRe: how to check " is not null condition" in a field of single select query Pin
WoutL6-Aug-09 3:07
WoutL6-Aug-09 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.