Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Joining 2 tables

Former Member
0 Likes
1,635

I am using the following select statement to select from 2 joined tables into an internal table:

  select DISTINCT zgtis_qtheader~qtenbr zgtis_qtheader~prjnam
         zgtis_qtheader~status zgtis_qtheader~expdte
    into table t_qtlist
    from zgtis_qtheader
      left join zgtis_qtline on
        ( zgtis_qtheader~mandt  = zgtis_qtline~mandt and
          zgtis_qtheader~qtenbr = zgtis_qtline~qtenbr
      and zgtis_qtheader~vers   = zgtis_qtline~vers )
    where (lv_where).

The shared key to the two tables is mandt, qtenbr and vers. I keep receiving the following error message:

At least one of the field names in the SELECT clause is not unique.

Can anybody tell me what I am doing wrong? I have each field preceded by the table it is coming from.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,606

Hi,

Can you describe your Where condition??I guess thats where the problem is.

15 REPLIES 15
Read only

Former Member
0 Likes
1,606

the select caluse is wrong.

Read only

Former Member
0 Likes
1,606

Hi You are not selecting any thing from zgtis_qtline

but you are joining..

regards

vijay

Read only

0 Likes
1,606

I am really only joining because the where statement uses criteria from the qtline table, but I really only want header values in the table. I guess you are saying I have to select at least one field from both tables.

Read only

0 Likes
1,606

Hi Denise,

Thats fine but can you paste the where condition..so that we can be sure that the error is not due to this.

Read only

0 Likes
1,606

No, you don't have to select something from the other table...... this passes a syntax check.




report zrich_0001 .


data: imara type table of mara with header line.


select distinct mara~matnr mara~matkl
         into corresponding fields of table imara
                from mara
                  left join marc
                      on mara~matnr = marc~matnr
                               where mara~matnr <> space.


Regards,

Rich Heilman

Read only

0 Likes
1,606

Yeah ,thats fine,but you didn't mention it.

regards

vijay

Read only

0 Likes
1,606

No need to select from that, But You need to Place some where condition in side where clause.

regards

vijay

Read only

Former Member
0 Likes
1,606
  select DISTINCT zgtis_qtheader~qtenbr zgtis_qtheader~prjnam
         zgtis_qtheader~status zgtis_qtheader~expdte
<b>        zgtis_qtline~xyzzz
        zgtis_qtline~abcdde 
        zgtis_qtline~123333</b>
    into table t_qtlist
    from zgtis_qtheader
      left join zgtis_qtline on
        ( zgtis_qtheader~mandt  = zgtis_qtline~mandt and
          zgtis_qtheader~qtenbr = zgtis_qtline~qtenbr
      and zgtis_qtheader~vers   = zgtis_qtline~vers )
    where (lv_where).
Read only

Former Member
0 Likes
1,606

In BOLD one try to replace the fields of zgtis_qtline.

then your query will work.

regards

vijay

try to reward for helful answers.

Read only

Former Member
0 Likes
1,606

What does lv_where look like?

Rob

Read only

0 Likes
1,606

Are you doing something like


where qtenbr = 'XXX'
and   vers   = 'YYY'

If so, you have to qualify these names with the table.

Rob

Read only

Former Member
0 Likes
1,606

Where clause Did you mentioned in your code is same as you mentioned , what is you are checking there...

regards

vijay

Read only

Former Member
0 Likes
1,607

Hi,

Can you describe your Where condition??I guess thats where the problem is.

Read only

Former Member
0 Likes
1,606

Hi Denise,

The onlu possible reason could be, the system not able to take the table name as alias, can try writing as,

from zgtis_qtheader as h

left join zgtis_qtline as l

otherwise, i dont see anything wrong with your select statement...

See below code...it didnt throw any error

DATA: BEGIN OF I_TAB OCCURS 0,

MATNR TYPE MATNR,

WERKS TYPE WERKS_D,

LGORT TYPE LGORT_D,

DISMM TYPE DISMM,

END OF I_TAB.

SELECT DISTINCT MARC~MATNR

MARC~WERKS

MARC~DISMM

INTO TABLE I_TAB

FROM MARC LEFT JOIN

MARD ON

( MARDMATNR = MARCMATNR AND

MARDWERKS = MARCWERKS ).

Regards,

Raj

Message was edited by: Rajasekhar Dinavahi

Read only

Former Member
0 Likes
1,606

Denise,

There may be nothing else wrong with your code other than your where clause. Whether you use aliases or not doesn't really matter. It is also not necessary that you select at least one field from both the tables you are trying to join. If in your where clause you are trying to compare fields from one of the tables against data in an internal table, try this:

where zgtis_qtline-"fieldname" in lv_where.

Also not that you have to compare individual fields of the table. You cannot compare everything at once.

Hope this helps.

Message was edited by: Feroz Buksh