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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:12:07+00:00 2026-05-10T23:12:07+00:00

One doubt in MSSQL. There are two tables in a databases. Table 1 named

  • 0

One doubt in MSSQL. There are two tables in a databases.

Table 1 named Property contain fields PRPT_Id(int),PRPT_Name(varchar), PRPT_Status(bit)

Table 2 named PropertyImages contain fields PIMG_Id(int),PIMG_ImageName(varchar),PRPT_Id(int),PIMG_Status(bit)

These two tables follow a one-to-many relationship. That means the each Property can have zero, one or more PropertyImages corresponding to it.

What is required is a query to display

PRPT_Id, PRPT_Name, ImageCount(Count of all images corresponding to a PRPT_Id where PIMG_Status is true. o if there arent any images), FirstImageName(if there are n images, the name of the first image in the image table corresponding to the PRPT_Id with PIMG_Status true. if there aren’t any images we fill that with whitespace/blank) . another condition is that PRPT_Status should be true.

Edit Note – Both the tables are having autoincremented integers as primary key. So first Image name will be the name with MIN(PIMG_Id), isn’t that so?

I want the PIMG_ImageName corresponding to the MIN(PIMG_ID) in the resultset

  • 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. 2026-05-10T23:12:07+00:00Added an answer on May 10, 2026 at 11:12 pm

    Assuming that FirstImage means the one with the lowest Id, then this should be at least close enough to test to completion:

    SELECT
    PRPT_Id,
    PRPT_Name,
    ISNULL(pi1.ImageName, ”) AS FirstImageName,
    COUNT(1) AS ImageCount

    FROM Property AS p

    LEFT JOIN PropertyImages AS pi
    ON p.PRPT_Id = pi.PRPT_Id

    LEFT JOIN PropertyImage AS pi1
    ON p.PRPT_Id = pi1.PRPT_Id

    LEFT JOIN PropertyImgage AS pi2
    ON p.PRPT_Id = pi2.PRPT_Id
    AND pi1.PIMG_Id > pi2.PIMG_Id

    WHERE PRPT_Status = TRUE
    AND pi1.PIMG_Status = TRUE
    AND pi2.PIMG_ImageName IS NULL

    The double LEFT JOIN assures that you get the first image record in pi1. If the ‘First’ rule is different, then adjust this join accordingly.

    This should be about as efficient as possible. It has no subqueries.

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

Sidebar

Related Questions

I have one doubt regarding audio processing for noise reduction. Is there any free
Basically, there is an attribute table and translation table - many translations for one
i have one doubt,i have created new project in eclipse with android 2.3.1 and
I have one doubt regarding casting. public void Test(out T a, out T b)
I have one doubt in string . How can we acess the memory of
I have one doubt concerning c# method overloading and call resolution. Let's suppose I
I'm having one doubt about the VIM ENCRYPTION key . I having a text
In following program . I have one doubt. I have declared one global variable
Can anybody tell me a good example of Singleton pattern? Also I've one doubt
I am new to opencv and I have a doubt with one of the

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.