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

How to write this select query?

Former Member
0 Likes
1,672

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
Read only

Former Member
0 Likes
1,647

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

regards

Kiran

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'.

11 REPLIES 11
Read only

Former Member
0 Likes
1,648

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

regards

Kiran

Read only

Former Member
0 Likes
1,647
SELECT * FROM table INTO s_table WHERE object = 'a' or object = 'b' or object = 'c'.
Read only

Former Member
0 Likes
1,647

Hi

SELECT * FROM table INTO s_table WHERE

object = 'a' or

object = 'b'

or object = 'c'.

Regards

Aditya

Read only

Former Member
0 Likes
1,647

Hi,

Write the select quiry as below.

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

Regards,

Murthy.

Read only

Former Member
0 Likes
1,647

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.)

Read only

0 Likes
1,647

Hi

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

Regards

Aditya

Read only

Former Member
0 Likes
1,647

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

Read only

Former Member
0 Likes
1,647

Hi Aditya,

The same object can have different value for differnt records.

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

Thanks.

Read only

0 Likes
1,647

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

Read only

Former Member
0 Likes
1,647

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.

Read only

Former Member
0 Likes
1,647

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.