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

  • Home
  • SEARCH
  • 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 7158733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:06:54+00:00 2026-05-28T13:06:54+00:00

My question, is there a faster way to the following query? I’m using ORACLE

  • 0

My question, is there a faster way to the following query?

I’m using ORACLE 10g

Say i have a table Manufacturer and Car, and i want to count all occurrences of the column ‘Car.Name’. here is How i’d do it:

SELECT manuf.Name, COUNT(car1.Name), COUNT(car2.Name), COUNT(car3.Name)
FROM Manufacturer manuf 
LEFT JOIN (SELECT * FROM Car c where c.Name = 'Ferrari1') car1 ON manuf.PK = car1.ManufPK
LEFT JOIN (SELECT * FROM Car c where c.Name = 'Ferrari2') car2 ON manuf.PK = car2.ManufPK
LEFT JOIN (SELECT * FROM Car c where c.Name = 'Ferrari3') car3 ON manuf.PK = car3.ManufPK
GROUP BY manuf.Name

Wanted Results:

Manufacturer | Ferrari1 | Ferrari2 | Ferrari3
----------------------------------------------
Fiat         |    1     |   0      |  5
Ford         |    2     |   3      |  0

I tried this with few LEFT JOINs, and it worked fine. But when i added a lot (like 90+), it was ultra slow (more than 1 minute).

My question, is there a faster way to do this 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-28T13:06:55+00:00Added an answer on May 28, 2026 at 1:06 pm

    If you are happy to see the cars counted down the page, try:

    select m.Name manufacturer_name,
           c.Name car_name,
           count(*)
    from Manufacturer m
    left join Car c 
           on m.PK = c.ManufPK and c.Name in ('Ferrari1','Ferrari2','Ferrari3')
    group by m.Name, c.Name
    

    If you need to see individual cars across the page, try:

    select m.Name manufacturer_name,
           sum(case c.Name when 'Ferrari1' then 1 else 0 end) Ferrari1_Count,
           sum(case c.Name when 'Ferrari2' then 1 else 0 end) Ferrari2_Count,
           sum(case c.Name when 'Ferrari3' then 1 else 0 end) Ferrari3_Count
    from Manufacturer m
    left join Car c 
           on m.PK = c.ManufPK and c.Name in ('Ferrari1','Ferrari2','Ferrari3')
    group by m.Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: Is there a way to load a lein plugin, say codex or lein-beanstalk,
I'm using ORMLite on Android and have the following question: Is it possible to
FYI, This is very similar to my last question: Is there a faster way
I have a job interview tomorrow and I'm trying to answer this question: There
Question Is there a way to define a method only once in C# (in
Question: Is there a way to check if a given font is one of
there's a question: Is there any way to pair Bluetooth device in Windows programmatically?
My question is there any way to better manage this database implementation. Background: Web
I have a quick question, suppose I have the following code and it's repeated
Newbie question: There are three types of Asp.Net controls : HTML server controls, Web

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.