Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    India
    Posts
    3

    Unanswered: 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

  2. #2
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

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

    Hope this helps,
    Grofaty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •