Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3782984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:09:35+00:00 2026-05-19T11:09:35+00:00

I need to loop through a set of values (less than 10) and see

  • 0

I need to loop through a set of values (less than 10) and see if they are in a table. If so, I need to print out all of the record values, but if the item doesn’t exist, I still want it to be included in the printed result, although with NULL or 0 values. So, for example, the following query returns:

select * 
  from ACTOR 
 where ID in (4, 5, 15);


+—-+—————————–+————-+———-+——+
| ID | NAME | DESCRIPTION | ORDER_ID | TYPE |
+—-+—————————–+————-+———-+——+
| 4 | [TEST-1] | | 3 | NULL |
| 5 | [TEST-2] | | 4 | NULL |
+—-+—————————–+————-+———-+——+

But I want it to return

+—-+—————————–+————-+———-+——+
| ID | NAME | DESCRIPTION | ORDER_ID | TYPE |
+—-+—————————–+————-+———-+——+
| 4 | [TEST-1] | | 3 | NULL |
| 5 | [TEST-2] | | 4 | NULL |
| 15| NULL | | 0 | NULL |
+—-+—————————–+————-+———-+——+

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:09:36+00:00Added an answer on May 19, 2026 at 11:09 am

    To get the output you want, you first have to construct a derived table containing the ACTOR.id values you desire. UNION ALL works for small data sets:

    SELECT *
      FROM (SELECT 4 AS actor_id
              FROM DUAL
            UNION ALL
            SELECT 5
              FROM DUAL
            UNION ALL
            SELECT 15
              FROM DUAL) x
    

    With that, you can OUTER JOIN to the actual table to get the results you want:

       SELECT x.actor_id,
              a.name,
              a.description,
              a.orderid,
              a.type
         FROM (SELECT 4 AS actor_id
                 FROM DUAL
               UNION ALL
               SELECT 5
                 FROM DUAL
               UNION ALL
               SELECT 15
                 FROM DUAL) x
    LEFT JOIN ACTOR a ON a.id = x.actor_id
    

    If there’s no match between x and a, the a columns will be null. So if you want orderid to be zero when there’s no match for id 15:

       SELECT x.actor_id,
              a.name,
              a.description,
              COALESCE(a.orderid, 0) AS orderid,
              a.type
         FROM (SELECT 4 AS actor_id
                 FROM DUAL
               UNION ALL
               SELECT 5
                 FROM DUAL
               UNION ALL
               SELECT 15
                 FROM DUAL) x
    LEFT JOIN ACTOR a ON a.id = x.actor_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to loop through a set of 2-dimensional array of hidden input fields
I need to loop through all the matches in say the following string: <a
I need to use VBScript to loop through a set of registry string value
i have the following code ..i need to loop through end of the file
Here's what I need to do: 1) Loop through every cell in a worksheet
A friend was in need of an algorithm that would let him loop through
I need to write some code that would loop though all rows of a
I need a for loop which would print from year 2000 to 2099. [Bindable]
I need to be able to loop through column names and put the coloumn
I need to loop over a query exactly 12 times to complete rows in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.