2008 Jul 30 5:36 AM
Hi experts,
what is the purpose of where clause in select query?
what I need to write in where clause?
please give detail description
2008 Jul 30 5:38 AM
Hi Prasad,
Where clause is for specifying a selection criteria and limiting your data. It filters data by search condition.
refer to the link:
http://help.sap.com/saphelp_nw04/helpdata/en/a8/4953eba3ad4cad9543dc2fac064308/content.htm
With luck,
Pritam.
2008 Jul 30 5:38 AM
Hi Prasad,
Where clause is for specifying a selection criteria and limiting your data. It filters data by search condition.
refer to the link:
http://help.sap.com/saphelp_nw04/helpdata/en/a8/4953eba3ad4cad9543dc2fac064308/content.htm
With luck,
Pritam.
2008 Jul 30 5:39 AM
hi,
Where clause is used to filter the selection. Using Where clause we can restrict the number of records in the SELECT query.
SELECT <fields>
fron <table>
into table <itab>
where <conditions>.
Regards
Sumit Agarwal
2008 Jul 30 5:39 AM
Hi,
Where clause in Select Query is used for giving the condition on which Data has be retreived from data base table.
In Where clause you mention the the Condition.
Check this link-
http://help.sap.com/saphelp_nw04/helpdata/en/a8/4953eba3ad4cad9543dc2fac064308/content.htm
Regards,
Sujit
2008 Jul 30 5:41 AM
Hi,
The WHERE clause is used to specify a selection criterion.
-
The WHERE Clause
To conditionally select data from a table, a WHERE clause can be added to the SELECT statement.
Syntax
SELECT column FROM table
WHERE column operator value
With the WHERE clause, the following operators can be used:
Operator Description
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN If you know the exact value you want to return for at least one of the columns
Note: In some versions of SQL the <> operator may be written as !=
-
Using the WHERE Clause
To select only the persons living in the city "Sandnes", we add a WHERE clause to the SELECT statement:
SELECT * FROM Persons
WHERE City='Sandnes'
"Persons" table
LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978
Svendson Stale Kaivn 18 Sandnes 1980
Pettersen Kari Storgt 20 Stavanger 1960
Result
LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978
Svendson Stale Kaivn 18 Sandnes 1980
-
Using Quotes
Note that we have used single quotes around the conditional values in the examples.
SQL uses single quotes around text values (most database systems will also accept double quotes). Numeric values should not be enclosed in quotes.
For text values:
This is correct:
SELECT * FROM Persons WHERE FirstName='Tove'This is wrong:
SELECT * FROM Persons WHERE FirstName=Tove
For numeric values:
This is correct:
SELECT * FROM Persons WHERE Year>1965This is wrong:
SELECT * FROM Persons WHERE Year>'1965'
-
The LIKE Condition
The LIKE condition is used to specify a search for a pattern in a column.
Syntax
SELECT column FROM table
WHERE column LIKE pattern
A "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.
-
Using LIKE
The following SQL statement will return persons with first names that start with an 'O':
SELECT * FROM Persons
WHERE FirstName LIKE 'O%'
The following SQL statement will return persons with first names that end with an 'a':
SELECT * FROM Persons
WHERE FirstName LIKE '%a'
The following SQL statement will return persons with first names that contain the pattern 'la':
SELECT * FROM Persons
WHERE FirstName LIKE '%la%' .
Reward Points if useful
Raghunath.S
9986076729
2008 Jul 30 5:43 AM
Hi Prasad,
Where clause is used while writing a select query.
Instead of writing a select a query as standalone like
select * from sflight into internal table it_flight.
It will select all the records frm the database which decreases the performance . Instead of writing select query this way we can write using where clause as:
select * from sflight into internal table it_flight
where CARRID = 'AA'.
it will select the records for which CARRID is equal to AA.
Using this we can make the query specific to the requirement instead of selecting all other records.
Hope this will help.
Regards,
Swarna Munukoti.
2008 Jul 30 5:44 AM
Hi Prasad,
If you are accepting any inputs from the user and depending on that you have to retrieve the data from the data base, then you have to give the condition on which you are selecting the data in the where clause. for example :
parameters :
p_matnr.
data :
itab like standard table of mara.
Select matnr
matkl
from mara
into itab
where matnr eq p_matnr.
Regards,
Swapna.
2008 Jul 30 5:45 AM
2008 Jul 30 5:47 AM
Hi prasad,
By using where clause we can check the Conditon..and limiting you the database access..
For ex :
select * from spfli where carrid = 'LH'.
move-corresponding spfli to itab.
append itab.
endselect.
In this example all lines from spfliin in which carrid field contains 'LH' are read on to teh internal table ITAB ,where they can be processed..
plz reward me if useful....
Regards,
Jayan
2008 Jul 30 5:48 AM
Hi Prasad.
I would like to suggest,
The main purpose of WHERE clause in SELECT clause is to restrict the number of lines and fetch only the specific records mentioned in the WHERE clause.
This reduces the DATABASE fetch time as well as reduces the load on the database.
Sample Select query with WHERE clause---->
SELECT carrid
connid
fldate
from sflight
into table
t_sflight
where carrid = p_carrid,
and connid = p_connid.
Where p_carrid and p_connid are the parameters to be accepted at the selection screen as input values.
I would like to suggest a reference,
[SAP HELP - Standard Reference - Selecting Lines|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/content.htm]
Hope that's usefull.
Good Luck & Regards.
Harsh Dave
2008 Jul 30 5:55 AM
HI Prasad,
we use select query to retrive data from database.
suppose we have one company's database for empoyee. this is having 1 million records.
using select query we can select this emplyoee details from the database.
where clause is used to restrict the number of hits or number of record. suppose i want detail of only one employee with emplyee id 1.
then query will be
select employee from company where empID = 1.
so only one record pertaining to empID 1 can be fetched.
where clause improves the perfomance of the system.
it also allow us to select particular records from a larg database.
we have number of options for using where clause.
> , >= , <, <= , in, between -> this all can be used in where clause. logical operations like AND, OR can be used in where clause.
hope this satisfies ur query.
reward the point if u find this answer useful
Romanch.
2008 Jul 30 5:58 AM
Hi,
WHERE clause in select statement is used to retrive the data from a database table and place it in an internal table based on the condition that we provide in the WHERE clause.
There are differnt types of SELECT statements.
1) If you are using SELECT SINGLE then in WHERE clause you must pass all the KEY fields of the Database table from which you are retreiving the data.
2) If you are using the normal SELECT statement then in WHERE clause you have to mention the conditions.
Eg:
Select f1 f2 f3
From DB1 into Table itab
WHERE (Condition)
In Conditions we can pass either KEY fields or the Selection Screen parametrs(Select-Options, Parameters) or Particular conditions like language Specific,etc.
Reward points if found useful.
Regards,
Srinivasa Janardhan.
2008 Jul 30 6:14 AM
HI prasad,
WHERE <condition> only selects the records that meet the WHERE condition cond
If you specify a WHERE clause in the SELECT, OPEN CURSOR, UPDATE or DELETE statement, the system only selects records from the table or tables in the FROM clause that meet the logical condition cond in it.
The WHERE <condition> specifies the conditions that the result of the selection must satisfy. By default, only data from the current client is selected (without you having to specify the client field specifically in the WHERE clause).
Example :- Displaying all Lufthansa flights:
DATA: WA_SPFLI TYPE SPFLI.
SELECT * FROM spfli INTO wa_spfli
WHERE carrid = 'LH'.
WRITE: / wa_spfli-cityfrom, wa_spfli-cityto.
ENDSELECT.
Best of luck,
Bumika
2024 Apr 17 12:23 PM
HI,
Where clause is reducing and filtering the data for required based on inputs..we can pass * also in Where clause in sap abap select..Please find the below code
SELECT berid,repobj,repobj_date,rqmt_date,matnr,werks
FROM pmmo_assignment
INTO TABLE @DATA(lt_pmmo)
WHERE repobj LIKE 'OR%' AND matnr IN @s_matnr.