35
Views
9
Comments
Error executing Query
Question

Here is my query:

SELECT 

    SE.*,

    API.*,

    SESSRFQ.*,

    LAP.[PRNumber],

    RQGD.*,

    RQISB.*,

    SESSAPL.*,

    SESSAPLIV.*


FROM LAP

INNER JOIN  API ON LAP.[PRN] = API.[PRN]

LEFT JOIN  SE ON API.[Id] = SE.[API_Id]  

LEFT JOIN  SESSRFQ ON SESSRFQ.[PR] = API.[PRN] 

    AND SESSRFQ.[ItemNumber] = API.[PRLine]

LEFT JOIN  RQGD ON SE.[T_Id] = RQGD.[T_Id]

LEFT JOIN  RQISB ON RQGD.[Id] = RQISB.[RQ_Id]

LEFT JOIN  SESSAPL ON API.[PRN] = SESSAPL.[PRN]

LEFT JOIN  SESSAPLIV ON SESSAPL.[Id] = SESSAPLIV.[ListingId]

WHERE API.[PRNumber] IN (@PrN)

GROUP BY LAP.[PRN]


If I set this query and run , so I gives error executing query error and if i remove group by so it runs well but gives duplicate records in table. 

if anyone can help me for this.

Hello,

Can you show the error and the parameter you put in the "@PrN"?

Normally if you don't want duplicate records you use "Distinct"... Group By is used for other purposes, specially if you want a field to be a counter or a sum.

after using distinct ,getting same output

SELECT DISTINCT

returns distinct rows. but you're fetching a lot of information. if you compare ALL the fields, there aren't duplicate rows... at least one field (an id, or something else) must be different.

Can you please drop correct query here, so that i understand

I could if i understood what you want... you should instead of getting everything specify only the columns that you want. Then you can use DISTINCT.

Hi, what are the fields needed for your query? The commenters are correct, using distinct will give you all recorded deduplicated since you request so many columns where the records are not unique and will look like a duplicate, 

please only select the columns you need and then use the distinct to de-duplicate. 


To use a GROUP BY all selected columns need to be in the GROUP BY statement, GROUP BY is mostly used to count or sum records, 


https://www.w3schools.com/sql/sql_groupby.asp 

Hi Aisha S, 

The select columns must be the same as used in group by

Other used fields that you might use not included in the "group BY" must have a function applied (max, min, count, avg, sum...) 

https://learnsql.com/blog/group-by-in-sql-explained/

Hope that it helps you 

Hi Aisha

Could you try removing the group by and on the select statement on the field LAP.[PRNumber] apply the distinct clause,  distinct(LAP.[PRNumber])

Hope that it helps you,  I think as said above you should select the columns by name and not the way by *

Best regards 

Hello,

It appears that you may be encountering a similar error while attempting to utilize the Group By clause.


To resolve this, you should specify the select list and indicate the columns you wish to select, rather than using ".*." Once you've done this, you'll be able to use the Group By clause without any issues.


Hope this helps you,

Thanks,

Narendra

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.