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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:20:21+00:00 2026-06-11T14:20:21+00:00

I am new to SQL. I need to run a one-time query at a

  • 0

I am new to SQL. I need to run a one-time query at a few different sites to get a count. The query needs to give me a count of all records based on a where clause. But I’m having trouble figuring out the syntax.

Here’s what I tried:

SELECT COUNT(KEYS.IDXKEYID) FROM KEYS, KEYFLAGS 
WHERE IDXLEVELID = 1 
AND KEYFLAGS.BKEYSEVERMADE = -1

Which gave me a crazy number.

Basically, IDXKEYID is a primary key, and exists in both the KEYS and KEYFLAGS table. I want a count of all IDXKEYID records in the database that meet the above WHERE clause critera. I just want 1 simple result in 1 column/row.

COUNT
-----
12346

Thanks in advance!

  • 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-11T14:20:23+00:00Added an answer on June 11, 2026 at 2:20 pm
    SELECT COUNT(DISTINCT KEYS.IDXKEYID) -- count each key only once
      FROM KEYS, KEYFLAGS 
     WHERE KEYS.IDXLEVELID = 1 
       AND KEYFLAGS.BKEYSEVERMADE = -1
       AND KEYS.IDXKEYID = KEYFLAGS.IDXKEYID -- you're missing this link
    

    Or you can write it using EXISTS

    SELECT COUNT(1) -- count each key only once
      FROM KEYS
     WHERE KEYS.IDXLEVELID = 1 
       AND EXISTS (
           SELECT *
             FROM KEYFLAGS
            WHERE KEYS.IDXKEYID = KEYFLAGS.IDXKEYID -- correlate
              AND KEYFLAGS.BKEYSEVERMADE = -1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm somewhat new to SQL and need help with query syntax. My issue involves
I am new to SQL Server 2008, and I need some help in query
I need to run the replication of one table in SQL Server 2005. Replication
I need to create an entirely new Sql Server 2008 database and want to
I am very new to SQL and i need to retreive a number of
I am new to SQL Server Report Builder 2.0 and I need to compare
I am very new to sql.The actual problem is much bigger. I need information
I need to restrict the development users from creating new schedules for SQL Agent
I need to add a new column to a MS SQL 2005 database with
Oracle's PL/SQL is fairly new to me, so I need some help understanding if

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.