DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: which way of querying is better

  1. #1
    Join Date
    Dec 2000
    Posts
    255
    Hi All

    I have a 2 tables which related to each other
    Nemaster(primary key is Oid) and
    Elements (Neid reference Oid)

    Now I have to run following query

    A) SELECT IPADDRESS FROM ELEMENTS WHERE NEID = (SELECT OID FROM NEMASTER WHERE EID = &ID);

    I can run the above query as below

    B) SELECT IPADDRESS FROM NEMASTER A, ELEMENTS B
    WHERE A.OID = B.NEID AND A.EID = @ID;

    If my Nemaster table is going to be bulkier and if I am using above queries in FUNCTIONS then how I should call the query. By method A or B.

    Amol

  2. #2
    Join Date
    Aug 2001
    Location
    chennai,bangalore
    Posts
    840
    I guess it would be best to use the first query since the subquery will be exeucted very fast as the primary key is indexec and u r passing a hard code value and only one table is scanned.And the main query will also be executed very fast since it has the required matching values in the where condition.

    hope this helps


    regards
    anandkl
    anandkl

  3. #3
    Join Date
    Feb 2000
    Location
    Singapore
    Posts
    1,758
    Compare the execution plan and cost for both the statements.

    One more thing, in your first query the subquery should only return one row otherwise the statment will fail.

    Sanjay

  4. #4
    Join Date
    Feb 2001
    Posts
    389
    It should not matter , as this kind of subquery shall be transformed into a join by Oracle, so should concentrate on tuning second query by creating an index on EID and OID.

Posting Permissions

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


Click Here to Expand Forum to Full Width