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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:13:55+00:00 2026-05-18T02:13:55+00:00

Two tables: a) svn3 with columns name revno compname b) archdetails with columns name

  • 0

Two tables:
a) svn3 with columns name revno compname
b) archdetails with columns name version compname inFlat

Shouldn’t these 2 queries output the same result. The output of query 2 is correct. What is wrong with query1?

query1:
select sum(CASE WHEN inFlat=1 THEN 1 ELSE 0 END) from archdetails inner join svn3 on archdetails.compname=svn3.compname where archdetails.name='ant' AND version='1.4' AND (revno='r274642' OR revno='r274578' OR revno='r274533')

query2:
select sum(CASE WHEN inFlat=1 THEN 1 ELSE 0 END) from archdetails where name='ant' AND version='1.4' AND compname IN (select compname from svn3 where revno ='r274642' OR revno='r274578' OR revno='r274533')

  • 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-18T02:13:56+00:00Added an answer on May 18, 2026 at 2:13 am

    If svn3 has more than one row with the same compname that also have one of the requested revno values, then query 1 will count each svn3 row once. Query 2 will only count each compname once. The IN clause is eliminating any duplicate compname entries in the second query.

    If you don’t want to count duplicate compname entries, then you need to group them in a subquery. One way to do that is using the IN clause like you did in query 2. Another option would be to use GROUP BY on a subquery, and name that subquery. Then join the named subquery to the archdetails table.

    If you’re trying to solve a performance problem, then I would suggest adding primary keys and foreign keys to the tables. I think that would speed things up.

    I’ve seen some comments that EXISTS is sometimes faster than IN, but I haven’t seen any evidence to back that up. You might want to experiment with that.

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

Sidebar

Related Questions

Given two tables APPLE and ORANGE, NAME APPLES Alice 5 Bob 10 Trudy 1
I have two tables, lets say table1 and table2 with common columns, id and
The two tables below can both hold the same data - a full year,
I have two tables: Events (ID, Name, Time, Recorder) Video (ID, StartTime, EndTime, Recorder,
I have two tables that are all the same, except one has a timestamp
I have two tables. threads with the columns ID, forumID, title, content, unixtime comments
I need to join two tables based on columns with different types. The first
I want to join two tables (each table has 200 columns) so the purpose
I have two tables. Table Emp id name 1 Ajay 2 Amol 3 Sanjay
Problem: Two tables, first one contains userid(constraint fk) and column 'name', second table contains

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.