Application Development 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: 

How to write this select query?

Former Member
0 Kudos
149

Hi ,

I need to write a select query which involves the selection of multiple values for the same field .

eg. I need to select the rows from a table which have field 'object' the values a and b and c ?

Is the following select query valid?

SELECT * FROM table INTO s_table WHERE object = 'a' and 'b' and 'c'.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
124

SELECT * FROM table INTO s_table WHERE object in ( 'a' 'b' 'c').

regards

Kiran

11 REPLIES 11

Former Member
0 Kudos
125

SELECT * FROM table INTO s_table WHERE object in ( 'a' 'b' 'c').

regards

Kiran

Former Member
0 Kudos
124
SELECT * FROM table INTO s_table WHERE object = 'a' or object = 'b' or object = 'c'.

Former Member
0 Kudos
124

Hi

SELECT * FROM table INTO s_table WHERE

object = 'a' or

object = 'b'

or object = 'c'.

Regards

Aditya

Former Member
0 Kudos
124

Hi,

Write the select quiry as below.

SELECT * FROM table INTO s_table WHERE object IN ( 'a' , 'b', 'c' ).

Regards,

Murthy.

Former Member
0 Kudos
124

Thanks for your answers..

But I want to select an object which neccesarily has all the three value (i.e. a and b and c assigned to it.)

0 Kudos
124

Hi

Is it possible that for a single record OBJECT is having all 3 different values

Regards

Aditya

former_member1245113
Active Contributor
0 Kudos
124

Hi,

Select * from sflight into table itab where carrid = 'AA' or

carrid = 'LH' OR CARRID = 'UA'.

IF SY-subrc is initial.

endif.

Best Regards

Ramchander Rao.K

Former Member
0 Kudos
124

Hi Aditya,

The same object can have different value for differnt records.

But for a single record , it only has one value.

Thanks.

0 Kudos
124

Hi,

So the object has different values for different records.

then this id wat you can do.

SELECT * FROM table INTO s_table WHERE object IN ( 'a','b','c').

Regards,

Manoj Kumar P

Former Member
0 Kudos
124

Hi,

IF you use like this you can't get.

do like this, i hope it will be help full.

Select * from table inti s_tbale where object = 'a', or object = 'b' or object = 'c'.

then in your s_table will have all the records comes under a , b and c.

then depeding on condition loop it.

Regards,

Arjun.

Former Member
0 Kudos
124

For your particular requirement it may not be possible to get a result set from query itself.

Fetch your data as suggested above using .. WHERE object IN ('a','b','c')

After this loop on your itab. For each record you should check if there is a corresponding record for object 'b' and 'c'.

Sample could be:

LOOP at itab where object = 'a'..

READ itab with key object = 'c' and ..other key fields

READ itab with key object = 'b' and ..other key fields

IF both return sy-subrc 0 then continue else delete.

ENDLOOP.