x

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, 2010 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, 2010 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, 2010 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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1850
x122
x11

asked: May 05, 2010 at 11:29 AM

Seen: 4832 times

Last Updated: May 05, 2010 at 11:29 AM