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 755711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:09:41+00:00 2026-05-14T15:09:41+00:00

i have two selects a & b and i join them like: select *

  • 0

i have two selects a & b and i join them like:

select * from 
(
   select n.id_b || ',' || s.id_b ids, n.name, s.surname 
   from names n, 
        surnames s where n.id_a = s.id_a
) a 
left join
(
    select sn.id, sn.second_name
) b on b.id in (a.ids)

in this case join doesn’t work 🙁
The problem is in b.id in (a.ids). But why if it looks like 12 in (12,24) and no result 🙁

  • 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-14T15:09:42+00:00Added an answer on May 14, 2026 at 3:09 pm

    This won’t work because (12,24) is a single discrete string not a comma-separated set of numbers. Clearly, 12 != '(12,24)', hence no results are returned.

    edit

    I missed the outer join in your posted query. So you ought to get something back, even though there is no join between the two tables. Here is some test data:

    SQL> select * from names
      2  /
    
          ID_A       ID_B NAME
    ---------- ---------- ----------
             1         12 SAM
    
    SQL> select * from surnames
      2  /
    
          ID_A       ID_B SURNAME
    ---------- ---------- ----------
             1         24 I-AM
    
    SQL> select * from whatever
      2  /
    
            ID SECOND_NAM
    ---------- ----------
            24 I AM SAM
    
    SQL>
    

    My query is similar to yours except I cast b.id as a string because a.ids is a string. If I don’t do this, the query fails with ORA-1722: invalid number.

    SQL> select * from
      2      (
      3           select n.id_b || ',' || s.id_b ids, n.name, s.surname
      4           from names n,
      5                surnames s
      6           where n.id_a = s.id_a
      7      ) a
      8  left join
      9      (
     10          select sn.id, sn.second_name
     11          from whatever sn
     12      ) b on to_char(b.id) in (a.ids)
     13  /
    
    IDS        NAME       SURNAME            ID SECOND_NAM
    ---------- ---------- ---------- ---------- ----------
    12,24      SAM        I-AM
    
    SQL>
    

    As you can see, it returns values from the left-hand query and nothing from the right, for the reason which I gave above.

    If you want to get something from both queries on the basis on partial matching of the IDs you need to do this:

    SQL> select a.ids
      2         , a.name
      3         , a.surname
      4         , b.id
      5         , b.second_name
      6  from
      7      (
      8           select n.id_b || ',' || s.id_b ids
      9                  , n.name
     10                  , s.surname
     11                  , n.id_b as n_id_b
     12                  , s.id_b as s_id_b
     13           from names n,
     14                surnames s
     15           where n.id_a = s.id_a
     16      ) a
     17  left join
     18      (
     19          select sn.id, sn.second_name
     20          from whatever sn
     21      ) b on (b.id = a.n_id_b or b.id = a.s_id_b )
     22  /
    
    IDS        NAME       SURNAME            ID SECOND_NAM
    ---------- ---------- ---------- ---------- ----------
    12,24      SAM        I-AM               24 I AM SAM
    
    SQL>
    

    If you take this latter approach you may want to consider turning the outer join into an inner. Depnds on you precise business rule.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It depends on the nature of the specific files that… May 14, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer -> Find an RSS feed of radar images for your… May 14, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer It seems the problem was strlen($matches[0]) returns 0 and 1… May 14, 2026 at 10:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.