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 6750081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:45:58+00:00 2026-05-26T12:45:58+00:00

Okay I have table: ID Name Description Picture 1 Alex Alex desc.. 2 2

  • 0

Okay I have table:

ID Name    Description   Picture
1  Alex     Alex desc..     2
2  Maria      NULL          3
3  John      John desc..   NULL

table picture has ID and varbinary image.

I need to select: If description exists, then description, else picture
I do this:

select Id,
       Name, 
       Case when Description is null then pic.Image else Description 
      from person per join picture pic on per.Picture = pic.Id

So, looks like unnecessary join if description is not null.
Anyways. any suggestions on improving this simple query? also, What are good easy to use tools for performance comparison between two version of queries?

  • 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-26T12:45:59+00:00Added an answer on May 26, 2026 at 12:45 pm

    As far as I know there is no way to conditionally join within a single query. I would probably rewrite what you have as:

    SELECT per.ID, per.Name, COALESCE(per.Description, pic.Image) as desc
    FROM Person as per
    LEFT JOIN Picture as pic
    ON per.picture = pic.ID
    

    I’m not sure how the performance compares, but it seems a little cleaner.

    As far as comparing queries goes, I would recommend looking at the execution plan for both and seeing if either are doing any scans. Here is some info on using execution plans for performance tuning:

    • http://www.sql-server-performance.com/2006/query-execution-plan-analysis/
    • http://beyondrelational.com/blogs/nakul/archive/2011/07/28/ssms-performance-tuning-using-graphical-execution-plans-missing-indexes-hints.aspx

    You can also use the Database Tuning Advisor as a quick way to check to see if you have the necessary indexes.

    Be careful to not spend too much time over optimizing either. While it’s good to keep an eye on both current performance and performance as your database grows, it’s easy to spend a lot of time on this without getting too much in return. If you have a good database structure and well written queries, then future optimizations shouldn’t be too much of a pain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables: Item (Table) no name price description Item-custom (Table) userid
Okay hello there I have 2 tables Route table which has route ID, frequency,
I am wondering if it is okay to have master and detail table for
Okay, here's the situation: We have a table of about 50 columns (created by
okay, i'm setting up a multi-user chat system. i have a messages table, that
Okay, I'm stumped here. I have a control that is comprised of a table.
okay i have found the way to run a video in a image.... the
Suppose I have a table with a column name varchar(20) , and I store
I have an entity which has an ID field: @Id @Column(name = `U##ID_VOIE`) @GeneratedValue(generator
okay I have some table like this.. table TopicForum ------------------------- - idforum (PK) -

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.