Problem solve Get help with specific problems with your technologies, process and projects.

SQL: One SELECT for one or several row, same WHERE.

select several rows or a row from a table.

Some times we need a same "SELECT" to select several rows or a row from a table. With this we have to use two instructions,...

"SELECT" with different conditions of searching in "WHERE".

Example: We use a same "SELECT" instructions:

This SELECT, it obtains from table_1, all fields where fld_date = 2003 year and 01 month.
FROM table_1
WHERE fld_date = 200301

But, what happens when you need only an ID, for the same date (200301)? You can condition the WHERE instruction with... (to see code).

If you aux_ID variable it has some ID valid. You need that specific ID, or you need all IDs.

SELECT fld_id, fld_name, fld_lastname, fld_date, .....
FROM   table_1
WHERE  fld_date = 200301 AND
       fld_id   = CASE
                  WHEN :aux_id > 0
                        THEN aux_id
                        ELSE fld_id


The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

This was last published in January 2003

Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.