Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6539045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:48:34+00:00 2026-05-25T10:48:34+00:00

In the following query, the join to table title_deed is only required for the

  • 0

In the following query, the join to table title_deed is only required for the title_deed_no search criterion, and no fields are selected from it. If the @titleDeedNumber parameter is null, will a join still be performed? How much difference would this make to performance anyway? I am trying to replace dynamic generation of a big ugly T-SQL string, and the code that does that only adds a join if a title_deed_no value is supplied.

DECLARE @registrarId nchar(1)
DECLARE @titleDeedNumber nvarchar(50)

SELECT TOP 100
        vw.*
FROM    ACC.dbo.vw_Property_Nad vw
        INNER JOIN title_deed td ON ( @titleDeedNumber IS NULL )
                                    OR ( td.Prop_ID = vw.prop_id )
WHERE   vw.Prop_ID IS NOT NULL
        AND Registrar = isnull(@registrarId, vw.Registrar)
        AND td.title_deed_no = isnull(@titleDeedNumber, td.title_deed_no)

I have tried examning the execution plan, but it is just too busy with joins from the vw_Property_Nad view, and I’d rather get an expert opinion anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:48:35+00:00Added an answer on May 25, 2026 at 10:48 am

    In this case, probably not.

    You’re better off with:

    • an EXISTS not JOIN (ie semi-join not equi-join)
    • (vw.Registrar = @registrarId OR @registrarId IS NULL)
    • ditto for td.title_deed_no in the EXISTS

    Also

    • TOP without ORDER BY is useless
    • Your JOIN condition implies CROSS JOIN -> you’d need DISTINCT to get it working
    • vw implies view -> the query is more complex than what you expect. A view is a macro that expands

    I’d also consider an IF or UNION ALL

    SELECT
            vw.*
    FROM    ACC.dbo.vw_Property_Nad vw
    WHERE   vw.Prop_ID IS NOT NULL
            AND (vw.Registrar = @registrarId OR @registrarId IS NULL)
            AND @titleDeedNumber IS NULL
    UNION ALL
    SELECT
            vw.*
    FROM    ACC.dbo.vw_Property_Nad vw
    WHERE   vw.Prop_ID IS NOT NULL
            AND (vw.Registrar = @registrarId OR @registrarId IS NULL)
            AND @titleDeedNumber IS NOT NULL
            AND EXISTS (...)
    ORDER BY something
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen people writing the following query SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2
I have the following MySQL query statement: SELECT * FROM table1 INNER JOIN table2
I have the following query: SELECT * FROM quotes INNER JOIN quotes_panels ON quotes.wp_user_id
I have the following query: SELECT COUNT(*) FROM FirstTable ft INNER JOIN SecondTable st
I have the following query SELECT * FROM attend RIGHT OUTER JOIN noattend ON
I have the following query: $img_sub_qry = SELECT * FROM images JOIN imagsub ON
I have the following query: SELECT DISTINCT w.name, count(*) FROM widgets AS w JOIN
I am running following query.. Select T1.* from T1 LEFT JOIN T2 ON T1.C1
The following left join query in MS Access 2007 SELECT Table1.Field_A, Table1.Field_B, qry_Table2_Combined.Field_A, qry_Table2_Combined.Field_B,
Hi i'm struggling to write a particular MySQL Join Query. I have a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.