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

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 first published in January 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.