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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:07:00+00:00 2026-06-15T17:07:00+00:00

As written in the title: How to write this SQL statement correctly? select sl.switch_ip,

  • 0

As written in the title: How to write this SQL statement correctly?

   select 
    sl.switch_ip,
    sl.switch_name, 
    count(m.switch_ip) as macentries,
    (select arpentries from (select sl1.switch_ip, sl1.switch_name, count(ar.switch_ip) as arpentries 
        from my_switchlist sl1 
        left Join my_arptable ar on ar.switch_ip = sl1.switch_ip
        group by sl1.switch_ip,sl1.switch_name 
        order by sl1.switch_ip))
    from my_switchlist sl 
        left Join my_mactable m on m.switch_ip = sl.switch_ip
    group by sl.switch_ip,sl.switch_name 
    order by sl.switch_ip

The select and the sub-select work fine if they are executed separately.
But as soon as I put them together I get the following error:

Error: A subquery has returned not exactly one row.
SQLState: 21000
ErrorCode: -284
Position: 470
  • 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-06-15T17:07:01+00:00Added an answer on June 15, 2026 at 5:07 pm

    Looks like you want both the ‘count’ aggregates, which should be possible with something like this:

    select
       macquery.switch_ip,
       macquery.switch_name,
       macquery.macentries,
       arpquery.arpentries
    from
    (
       select 
          sl.switch_ip as switch_ip,
          sl.switch_name as switch_name,  
          count(m.switch_ip) as macentries
       from my_switchlist sl 
       left outer join my_mactable m
       on m.switch_ip = sl.switch_ip
       group by
          sl.switch_ip,
          sl.switch_name 
    ) macquery
    
    join
    
    (
       select
          sl1.switch_ip as switch_ip,
          sl1.switch_name as switch_name,
          count(ar.switch_ip) as arpentries 
       from my_switchlist sl1 
       left outer join my_arptable ar
       on ar.switch_ip = sl1.switch_ip
       group by
          sl1.switch_ip,
          sl1.switch_name 
    ) arpquery
    
    on  (macquery.switch_ip =  arpquery.switch_ip
        and  macquery.switch_name =  arpquery.switch_name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I had written in title, I have SQL query, run on Oracle DB,
I'm sorry, I have no idea how to title this question. I've written an
I have a sales simulator written in C#. I did not write this however
So basically I want to write a function that can be written like this:
(Title was: How to write a unit test for a DBUS service written in
I currently have this written but the title says is there a better way
On my website, I have an upload story feature with a user written title
I have written a code which does the thing as the title says. The
I'm often having code written as follows try: self.title = item.title().content.string except AttributeError, e:
Sorry for dodgy title, couldn't think of anything better... Anyway, I have written a

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.