Hari
Hari

Reputation: 191

Inner join error

enter image description here

How to join this 2 tables? Common column is ref#no.

But I get an error

Column 'Ink Delivery.DELDATE' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

SELECT 
    a.REF#NO, a.DELDATE, a.REQUST_By, a.PROJ_CODE, 
    b.PR_CODE, b.INK_CODE, b.QTY, b.PRICE 
from [Ink Delivery detals] b
inner join [Ink Delivery] a ON a.REF#NO = b.REF#NO
GROUP by a.REF#NO

Upvotes: 0

Views: 250

Answers (2)

Kalla
Kalla

Reputation: 165

SELECT 
    a.REF#NO, a.DELDATE, a.REQUST_By, a.PROJ_CODE, 
    b.PR_CODE, b.INK_CODE, b.QTY, b.PRICE 
from [Ink Delivery detals] b
inner join [Ink Delivery] a ON a.REF#NO = b.REF#NO
ORDER BY a.REF#NO

is the correct way.

Upvotes: 3

Randy Minder
Randy Minder

Reputation: 48522

This is not an inner join problem. Look at the error you getting. You are attempting to do a Group By, but you have columns in your Select statement that are not contained in the Group By clause. When doing a Group By, your Select statement can only contain columns referenced in the Group By clause or aggregate columns (e.g., Sum, Average).

You might want to brush on how to use Group By in SQL Server.

Upvotes: 3

Related Questions