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

  • Home
  • SEARCH
  • 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 8988169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:57:39+00:00 2026-06-15T21:57:39+00:00

I have following sql query and my left join is not giving me distinct

  • 0

I have following sql query and my left join is not giving me distinct result please help me to trace out.

       SELECT  DISTINCT
                    Position.Date,
                    Position.SecurityId,
                    Position.PurchaseLotId,
                    Position.InPosition,
                    ISNULL(ClosingPrice.Bid, Position.Mark) AS  Mark
        FROM
                Fireball_Reporting.dbo.Reporting_DailyNAV_Pricing POSITION WITH (NOLOCK, READUNCOMMITTED)
                LEFT JOIN Fireball.dbo.AdditionalSecurityPrice ClosingPrice WITH (NOLOCK, READUNCOMMITTED) ON
                            ClosingPrice.SecurityID = Position.PricingSecurityID AND
                            ClosingPrice.Date = Position.Date AND
                            ClosingPrice.SecurityPriceSourceID = @SourceID AND
                            ClosingPrice.PortfolioID IN (5,6)  

 WHERE
        DatePurchased > @NewPositionDate AND
        Position.Date = @CurrentPositionDate AND
        InPosition = 1 AND

        Position.PortfolioId IN ( 
                                SELECT 
                                    PARAM 
                                FROM 
                                    Fireball_Reporting.dbo.ParseMultiValuedParameter(@PortfolioId, ',') 
                                ) AND
        (
        Position > 1 OR
        Position < - 1
        )

Now here in above my when I use LEFT JOIN ISNULL(ClosingPrice.Bid, Position.Mark) AS Mark and LEFT JOIN it is giving me more no of records with mutiple portfolio ids
for e.g . (5,6)

If i put portfolioID =5 giving result as 120 records

If i put portfolioID =6 giving result as 20 records

When I put portfolioID = (5,6) it should give me 140 records
but it is giving result as 350 records which is wrong . 🙁

It is happening because when I use LEFT JOIN there is no condition of PurchaseLotID in that as table Fireball.dbo.AdditionalSecurityPrice ClosingPrice not having column PurchaseLotID so it is giving me other records also whoes having same purchaseLotID’s with diferent prices .

But I dont want that records

How can I eliminate those records ?

  • 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-06-15T21:57:40+00:00Added an answer on June 15, 2026 at 9:57 pm

    The most likely cause is that the left join produces duplicated PurchaseLotIds. The best way to know if if you perform a select distinct(PurchaseLotId) on your left side of the inner join.

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

Sidebar

Related Questions

I have the following SQL statement: SELECT * FROM cars car LEFT JOIN (SELECT
I have following SQL query but this is not quite what I want: SELECT
I have following SQL Query SELECT * FROM KDMS_dynamic vd INNER JOIN KDMS_definition tblKDMS
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
I have the following SQL query: SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG
I have the following SQL query SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG
I have the following SQL query I was given, but I am not sure
Let's say I have the following SQL query SELECT id, name, title, description, time
I have the following SQL Server query: SELECT area FROM places WHERE REPLACE(area,'-',' ')
Let's say I have the following SQL query: SELECT Meeting.id AS meetingId, Bill.id AS

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.