x
login about faq Site discussion (meta-askssc)

column was specified multiple times when using a join

Hi Im getting the error

Msg 8156, Level 16, State 1, Line 15 The column 'ACTIONTYPE' was specified multiple times for 'paged'.

when running this query

WITH paged AS

(

SELECT *, ROW_NUMBER() OVER (ORDER BY DESCRIPTION) AS 'rowNumber'

FROM [IQ_ITEM]

FULL JOIN IQ_PROMOTIONSITEMS ON IQ_ITEM.NO = IQ_PROMOTIONSITEMS.ITEMNO

WHERE IQ_POMOTIONSITEMS.ITEMNO = IQ_ITEM.NO

AND DONOTSHOW = '0'

AND CODE='%'

AND NO+DESCRIPTION LIKE'%'

)

SELECT * FROM paged WHERE rowNumber BETWEEN 1 and 10;

is there anyway to exclude columns from the joined table so i dont get this error? or any ideas on how to alter this query

Thanks in advance

more ▼

asked May 05 '10 at 11:29 AM in Default

Phil 1 gravatar image

Phil 1
1 1 1 1

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

You need to specify the column from each table that you want in the CTE definition and not do a "select *", see below. I have aliased the table named to make it a little clearer which columns com from which table. If the column exists in both tables you need to put a column list in place so the query processor knows which one you want to display.

WITH paged AS            
            
(            
            
SELECT IQI.col1, IQI.col3, IQP.col1, IQP.col2, ROW_NUMBER() OVER (ORDER BY DESCRIPTION) AS 'rowNumber'            
            
FROM [IQ_ITEM] IQI            
            
FULL JOIN IQ_PROMOTIONSITEMS IQP ON IQ_ITEM.NO = IQ_PROMOTIONSITEMS.ITEMNO            
            
WHERE IQ_POMOTIONSITEMS.ITEMNO = IQ_ITEM.NO            
            
AND DONOTSHOW = '0'            
            
AND CODE='%'            
            
AND NO+DESCRIPTION LIKE'%'            
            
)            
more ▼

answered May 05 '10 at 04:38 PM

Jason Cumberland gravatar image

Jason Cumberland
507 2

(comments are locked)
10|1200 characters needed characters left

You have ACTIONTYPE column in both tables that you join in the CTE. Modify the query to list all columns that you need explicitly, selecting * is not the best idea.

more ▼

answered May 05 '10 at 04:35 PM

Piotr Rodak gravatar image

Piotr Rodak
262 2

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1601
x100
x10

asked: May 05 '10 at 11:29 AM

Seen: 2598 times

Last Updated: May 05 '10 at 11:29 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.