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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:12:16+00:00 2026-05-25T03:12:16+00:00

I have a query that I am currently getting the ORA-01427: single-row subquery returns

  • 0

I have a query that I am currently getting the ORA-01427: single-row subquery returns more than one row error on. I understand the error, and what is causing it, but cant figure out a way to fix it. I would also like to do this in just one query. Here is what I currently have:

SELECT   v1.internal_code,
       (SELECT   terms_id
          FROM   terms
         WHERE   term_start_date =
                    (SELECT   MIN (term_start_date)
                       FROM   terms
                      WHERE   terms_id LIKE '%SU'
                              AND term_start_date >
                                    (SELECT   term_start_date
                                       FROM      terms
                                              JOIN
                                                 vals
                                              ON terms_id =
                                                    internal_code
                                      WHERE   internal_code =
                                                 v1.internal_code
                                              AND valcode_id =
                                                    'TERMS')))
          AS mmTerm
FROM      terms
       JOIN
          vals v1
       ON terms_id = internal_code
  WHERE   internal_code LIKE '%SP' AND valcode_id = 'WEB.SEARCH.TERMS'
 ORDER BY   mmTerm ASC

And the relevant part of the vals table would be this:

internal_code      valcode_id
-------------      ----------
   2003SP            TERMS
   2004SP            TERMS
   2005SP            TERMS

Okay, so the big subquery is attempting to get any terms that end with ‘SU’ where the term_start_date is greater than the term_start_date of the terms in the vals table. So the desired result is:

v1.internal_code      mmTerm
----------------      ------
    2003SP            2003SU
    2004SP            2004SU
    2005SP            2005SU

I know this is tough to understand, so please ask questions if there are any. Also, any suggestions are gladly accepted. Thanks!

EDIT: I figured it out. Just had to do some reworking, thanks for the suggestions. I will post it if anyone is interested in seeing the final query

  • 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-25T03:12:16+00:00Added an answer on May 25, 2026 at 3:12 am

    That’s quite hard to read – you need to add aliases to all the table references. The error can be gotten around if you don’t care about which row the subquery returns – simply return MIN(terms_id) or MAX(terms_id) or whatever to only bring back 1 row. But you may need to think about your data more deeply – does it really matter which term the subquery returns?

    SELECT   v1.internal_code,
           (SELECT   MIN(terms_id)
              FROM   terms
             WHERE   term_start_date =
                        (SELECT   MIN (term_start_date)
                           FROM   terms
                          WHERE   terms_id LIKE '%SU'
                                  AND term_start_date >
                                        (SELECT   term_start_date
                                           FROM      terms
                                                  JOIN
                                                     vals
                                                  ON terms_id =
                                                        internal_code
                                          WHERE   internal_code =
                                                     v1.internal_code
                                                  AND valcode_id =
                                                        'TERMS')))
              AS mmTerm
    FROM      terms
           JOIN
              vals v1
           ON terms_id = internal_code
      WHERE   internal_code LIKE '%SP' AND valcode_id = 'WEB.SEARCH.TERMS'
     ORDER BY   mmTerm ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that is currently using a correlated subquery to return the
I currently have a SQL query that returns a number of fields. I need
Hey guys I have a query that currently finds the latest comment for each
I have a select query that currently produces the following results: Description Code Price
Dear all, I have a select query that currently produces the following results: DoctorName
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I have a query on my homepage that is getting slower and slower as
I'm currently getting the error: java.sql.SQLException: ORA-01843: not a valid month which I assume
I have a combo box that is currently getting its information from a database
I am using in C# MYsql .I have query that works if I run

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.