Results 1 to 4 of 4

Thread: Query Performance

  1. #1
    Join Date
    Apr 2007
    Posts
    1

    Query Performance

    Hi All,
    Can any one tell me which of the following queries will be faster and its reason for it.

    query-1:

    SELECT
    (SELECT Name FROM ActionAudit WHERE id = ActionId) as ActionName,
    (SELECT IconId FROM ActionAudit WHERE id = ActionId) as IconId,
    (SELECT UserName FROM SessionSecurity WHERE id = A.SessionId) as UserName,
    (SELECT SecurityId FROM SessionSecurity WHERE id = A.SessionId) as SecurityId,
    (SELECT ProfileName FROM SessionSecurity WHERE id = A.SessionId) as ProfileName,
    (SELECT ClientName FROM SessionSecurity WHERE id = A.SessionId) as ClientName,
    (SELECT ComputerName FROM SessionSecurity WHERE id = A.SessionId) as ComputerName,
    (SELECT IPAddress FROM SessionSecurity WHERE id = A.SessionId) as IPAddress,
    (SELECT MacAddress FROM SessionSecurity WHERE id = A.SessionId) as MacAddress,
    (SELECT InDateTime FROM SessionSecurity WHERE id = A.SessionId) as InDateTime,
    (SELECT OutDateTime FROM SessionSecurity WHERE id = A.SessionId) as OutDateTime
    FROM
    LogAudit A

    Query-2:

    SELECT
    AA.Name as ActionName,
    AA.IconId,
    UserName,
    SecurityId,
    ProfileName,
    ClientName,
    ComputerName,
    IPAddress,
    MacAddress,
    InDateTime,
    OutDateTime
    FROM
    LogAudit A
    INNER JOIN
    ActionAudit AA ON A.ActionId=AA.Id
    INNER JOIN
    SessionSecurity SS ON A.SessionId=SS.Id

    thanks,
    Karthik.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    If use sql server, you can run both in same batch and check execution plan to see which one costs less.

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    I am pretty sure the second one runs faster, you have too many selects from the same table in the first one.

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254

Posting Permissions

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