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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:49:30+00:00 2026-06-04T03:49:30+00:00

I have one table that I’m using to store all access requests for a

  • 0

I have one table that I’m using to store all access requests for a radius server, that looks like this:

describe radius.loginattempts;
+------------------+------------------+------+-----+---------+----------------+
| Field            | Type             | Null | Key | Default | Extra          |
+------------------+------------------+------+-----+---------+----------------+
| loginattempt_key | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| log_date         | int(10) unsigned | NO   |     | NULL    |                |
| result           | tinyint(1)       | YES  |     | NULL    |                |
| username         | text             | YES  |     | NULL    |                |
| mac              | text             | YES  |     | NULL    |                |
+------------------+------------------+------+-----+---------+----------------+

Every time someone tries to log in, whether it works or not, a log entry gets created in this table.

What I want to do is get a list of all the devices that have had two or more users try to log in, and all the distinct usernames for each.

So, if I have some data that looks like this:

select * from loginattempts limit 8;
+------------------+------------+--------+----------+-------------------+
| loginattempt_key | log_date   | result | username | mac               |
+------------------+------------+--------+----------+-------------------+
|                1 | 1337035334 |      1 | kclark   | 11:11:11:11:11:11 |
|                2 | 1337035620 |      1 | kclark   | 22:22:22:22:22:22 |
|                3 | 1337035681 |      0 | guest    | 33:33:33:33:33:33 |
|                4 | 1337035740 |      1 | guest    | 22:22:22:22:22:22 |
|                5 | 1337037782 |      1 | rfogarty | 44:44:44:44:44:44 |
|                6 | 1337037789 |      1 | jsmith   | 44:44:44:44:44:44 |
|                7 | 1337037790 |      1 | jsmith   | 44:44:44:44:44:44 |
|                8 | 1337037791 |      1 | jsmith   | 44:44:44:44:44:44 |
+------------------+------------+--------+----------+-------------------+

I want one magic query that returns something like this:

+-------------------+----------+
| mac               | username |
+-------------------+----------+
| 22:22:22:22:22:22 | kclark   |
| 22:22:22:22:22:22 | guest    |
| 44:44:44:44:44:44 | rfogarty |
| 44:44:44:44:44:44 | jsmith   |
+-------------------+----------+

This will eventually be in PHP, and I can easily do it with two queries and a for loop, but as a thought experiment I’ve been trying to think of how to do it with a single query and some fancy joins (or even subqueries) but just can’t wrap my head around it…

mysql -V
mysql  Ver 14.14 Distrib 5.1.52, for unknown-linux-gnu (x86_64) using readline 5.1
  • 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-04T03:49:35+00:00Added an answer on June 4, 2026 at 3:49 am

    OK, I think you mean this…http://sqlfiddle.com/#!3/b6100/6

    Given

    create table loginattempts  
    (
      login_key int,
      mac varchar(12) null,
      username varchar(12) null
    )
    
    insert into loginattempts values (1, 111, 'peter')
    insert into loginattempts values (2, 111, 'bob')
    insert into loginattempts values (3, 222, 'geoff')
    insert into loginattempts values (4, 222, 'lisa')
    insert into loginattempts values (1, 333, 'peter')
    

    You need this query

       select mac, username
       from loginattempts
       where
        mac in
        (
          select mac
          from loginattempts
          group by mac
          having count(*) > 1
         )
    

    Gives you

    MAC USERNAME
    111 peter
    111 bob
    222 geoff
    222 lisa
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table that looks something like this: id parent_id name 1 0
I have one sql table that looks like this called posts: id | user
Suppose i have one table that holds Blogs. The schema looks like : ID
i have one table sql server like below , from that table i want
Lets say I have one table called REVIEWS This table has Reviews that customers
I have a ms access database that has one table for each photo album
I have a MS ACCESS 2003 datatbase that have one table in it TABLEA.
I'm attempting to delete all rows in one table that do not have a
I have one table named Staff in access and also have this table(same name)
I have one table that has sales records and another table that has additional

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.