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

comparing fields in SELECT statement

Former Member
0 Likes
988

Hey guys,

is there a way to build ONE select statement where the logic expressions compares two  fields of the database table?

e.g.:

select * from TABLE

     where FIELD_1 <> FIELD_2.

thx, M.

7 REPLIES 7
Read only

bernat_loscos
Explorer
0 Likes
959

Hi,

You need use the operator 'AND' ??

Do you mean that?

select * from mara

     where matnr <> matkl

       AND loekz <> 'X'.

Regards

Read only

0 Likes
959

both fields are fields in the table. I want to select those entries, which have different entries in the fields.

Read only

0 Likes
959

It is a weird query. I am sure that exist another way to solve your problem...

Regards,

Read only

narendar_naidu
Active Participant
0 Likes
959

hi,

you mean two fields of the same table.

if that is the case , then you cannot do it.

Reason , in where clause  u cannot compare two fields of the same table.

regards,

Read only

RaymondGiuseppi
Active Contributor
0 Likes
959

You have to "qualify" the second fields,

  • WHERE fieldname1 NE fieldname2 " invalid
  • WHERE fieldname1 NE tablename~fieldname2 " valid

Read documentation of WHERE - sql_cond in online SELECT statement documentation.

Regards,

Raymond

Read only

philipdavy
Contributor
0 Likes
959

This message was moderated.

Read only

narendar_naidu
Active Participant
0 Likes
959

Hi All,

Im sorry for my reply, raymond and philip are right , yes it works.

regards.