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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:31:56+00:00 2026-06-14T14:31:56+00:00

I have two tables that have data that I need a count from Login

  • 0

I have two tables that have data that I need a count from

Login History
and
Login Attempts

One is a Login History table that does not include Login Attemtps.

The primary key of Login History is REF_ID, but also contains Customer_ID. The Login Attempts table’s also includes Customer_ID

I’m trying to get a count of login attempts and login history for specific Customer_id’s. I’ve gotten a list of Customer_ID’s and placed them in a temporary table “#a”
Here’s the query I’m trying to use to get this count.

SELECT COUNT (la.customer_ID) as login_attempts FROM
LOGIN_ATTEMPTS la
JOIN LOGIN_HISTORY lh
on la.Customer_ID = lh.customer_ID
where la.customer_ID in (select Customer_ID from #a)group by la.customer_ID

The result set I would need is the Customer_ID’s, and the count for each Customer’s login attempts and history next to it. I’ve tried a few different ways, and I always end up with errors with my GROUP BY or COUNT syntax.

I’m also assuming I could add a SUM function in here somewhere but I’m not sure how I would need to structure it. Thanks for the help 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-14T14:31:57+00:00Added an answer on June 14, 2026 at 2:31 pm

    This is a variation on @bummi’s second approach, without the additional subqueries:

    Select customer_ID,
           sum(case when ltype = 'A' then 1 else 0 end) as LoginAttempts,
           sum(case when ltype = 'H' then 1 else 0 end) as LoginHistory
    from ((select 'A' as ltype, customer_ID
           from LOGIN_ATTEMPTS
          ) union all
          (select 'H' as ltype, customer_id
           from LOGIN_HISTORY
          ) 
         ) l
    where customer_Id in (select Customer_Id from #A)
    group by customer_Id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an INSERT query that is pulling data from two tables and inserting
I have two tables that link together through an id one is submit_moderate and
I have two tables that are related via a mapping table: keywords titles I
Suppose I have two tables that are linked (one has a foreign key to
I have two tables. In one table we enter all types of Models, each
I have two tables, one showing items users have bought from various stores, and
I have data from two spreadsheets where I need to compare the quantities of
I have two database tables containing similar data - one is the amount of
I have two tables that have virtually identical content and very similar structure. They
I have two tables that I want to join together. Table1 Year, ID, Theme,

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.