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 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

I've got two tables: TableA ------ ID, Name TableB ------ ID, SomeColumn, TableA_ID (FK
Say I have two tables I want to join. Categories: id name ---------- 1
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have two similar queries on same table and same where condition but different
I have two tables in database: A: [ ID, name, SECRET_KEY] examplary rows: ID1,
Two tables: COURSE_ROSTER - contains COURSE_ID as foreign key to COURSES USER_ID as field
Consider two tables transaction and category each having their own ID and information. A
Given two tables, one for workers and one for tasks completed by workers, CREATE
I've got two tables in my database: Articles and Tags The Tags tables consist
I have two tables that are joined together. A has many B Normally you

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.