If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Query to check the presence of a record : Efficient way

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-01-03, 07:47
dilip dilip is offline
Registered User
 
Join Date: Nov 2003
Location: India
Posts: 3
Query to check the presence of a record : Efficient way

Hi,

I need to write a query to find whether a particular record exists or not in a table. Basically I want the query to return a single value if the record is found.

Below are the possible solutions

SELECT 1
FROM MSG_STATUS
WHERE MSST_MSG_CTRL = 'H50344'
FETCH FIRST 1 ROW ONLY

SELECT distinct 1
FROM MSG_STATUS
WHERE MSST_MSG_CTRL = 'H50344'

SELECT COUNT(*)
FROM MSG_STATUS
WHERE MSST_MSG_CTRL = 'H50344'

SELECT 1
FROM SYSIBM.SYSDUMMY1 A
WHERE EXISTS (
SELECT 1 FROM
FROM MSG_STATUS
WHERE MSST_MSG_CTRL= 'H50344'
AND A.IBMREQD = A.IBMREQD
)

Is there any other way I can know whether the record is there or not .. performance is really a issue has the table contains records in lakhs or more

Pls let me know…

Regards

dilip
Reply With Quote
  #2 (permalink)  
Old 12-01-03, 08:54
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

1. Try using explain to find out the costs.
2. Consider of making index on column MSST_MSG_CTRL.

Hope this helps,
Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On