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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:22:09+00:00 2026-05-16T20:22:09+00:00

If I have this table: +——+——-+—————+——–+—————–+————+———–+—————-+——+——+——–+————+————+ | type | class | username | userid

  • 0

If I have this table:

+------+-------+---------------+--------+-----------------+------------+-----------+----------------+------+------+--------+------------+------------+
| type | class | username      | userid | userip          | usermobile | useremail | daysleft| pin1 | pin2 | pin3 | active | schoolname | schoolsite |
+------+-------+---------------+--------+-----------------+------------+-----------+----------------+------+------+--------+------------+------------+
| B    | A     | sebbetest     |   1000 | 123.123.123.123 | none       | none      |       50| 0    | 0    | 0    | Y      | none       | none       | 
| A    | A     | stackowerflow |   5355 | 123.123.123.123 | none       | none      |       50| 0    | 0    | 0    | Y      | none       | haha       | 
| C    | A     | good          |   4223 | 123.123.123.124 | none       | none      |       50| 0    | 0    | 0    | Y      | none       | haha       | 
| A    | A     | tester        |   6353 | 123.123.123.125 | none       | none      |       50| 0    | 0    | 0    | Y      | none       | haha       | 
| B    | A     | admin         |   3453 | 123.123.123.125 | none       | none      |       50| 0    | 0    | 0    | Y      | none       | eeee       | 
| A    | A     | sebastian     |   1342 | 123.123.123.126 | none       | none      |       50| 0    | 0    | 0    | Y      | none       | eeee       | 
| C    | A     | username      |   6456 | 123.123.123.125 | none       | none      |       50| 0    | 0    | 0    | Y      | none       | woooooow   | 
+------+-------+---------------+--------+-----------------+------------+-----------+----------------+------+------+--------+------------+------------+

As you see, the user “good” with the IP “123.123.123.124” AND user “sebastian” with IP “123.123.123.126” has no “companions”, no other users on the same IP.

The user “sebbetest” has a companion “stackowerflow”.

The user “tester” has 2 companions: “admin” and “username”.

Now I want to delete these users that lack companions. How I do? For atomic reasons and to prevent concurrent access from munging the database, I would want to delete all “non-companion” users in a single expression of SQL.

I tried with:
DELETE FROM lan WHERE COUNT(userip) = 1;

got this:
ERROR 1111 (HY000): Invalid use of group function

No rows are duplicates.
If there is a need to check if a entry is unique regardless of IP, (type, userid) is unique.

In other words, if IP is unique in a row, delete it.

  • 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-16T20:22:10+00:00Added an answer on May 16, 2026 at 8:22 pm

    Use:

    DELETE FROM lan
     WHERE userip IN (SELECT x.userip
                       FROM (SELECT yt.userip
                               FROM lan yt
                           GROUP BY yt.userip
                             HAVING COUNT(*) = 1) x )
    

    You get the error because you can’t use COUNT, or any other aggregate functions in the WHERE clause while outside of a subquery. Only in the HAVING clause can you reference aggregate functions in that manner.

    It’s possible this might work:

      DELETE FROM lan 
    GROUP BY userip
      HAVING COUNT(*) = 1;
    

    Warning

    With every DELETE statement, check and double check that the statement will select what you want for deletion. If you are using InnoDB tables, wrap the DELETE in a transaction so you can use ROLLBACK if necessary.

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

Sidebar

Related Questions

I have this table UserID SessionID SessionStart SessionEnd ----------------------------------------------- 1 abc1 2010-1-1 2010-1-2 5
I have this table called Table1 as follows: UserID Date 1 01/01/09 1 14/01/09
I have this table: create table demo ( key number(10) not null, type varchar2(3)
I have this table where I can generate dynamic rows (which has input <type=text
I have this table: <table class=mytbl> <thead> <tr> <th>dyn-tbl-hdr-1</th> <----these actually are timestamps. <th>dyn-tbl-hdr-2</th>
I have this table view UserName Product NumberPurchaces -------- ------- --------------- 'John Doe' 'Chair'
I have this table class: class Songs extends Zend_Db_Table_Abstract { protected $_name = 'songs';
I have this table: Month Type JAN A JAN A FEB B FEB B
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this table: UNIQUE_ID | WINNER_ID | FINALIST_ID ________1 | ________1 | __________2

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.