codingManiac
codingManiac

Reputation: 1700

Group by a column without including in Select list

I need to group by multiple columns and insert the results into a table but one of the columns I need to group by isn't to be inserted, such as the following...

INSERT INTO tbl (fld1, fld2, fld3, fld4)
SELECT DISTINCT fld1, fld2, fld3, fld4, fld5

It won't let me insert the records because of the extra column that I need grouped. Is there a potential workaround for this?

Upvotes: 0

Views: 116

Answers (1)

Anon
Anon

Reputation: 10908

INSERT INTO tbl (fld1, fld2, fld3, fld4)
SELECT fld1, fld2, fld3, fld4
GROUP BY fld1, fld2, fld3, fld4, fld5

Upvotes: 3

Related Questions