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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:31:15+00:00 2026-05-23T18:31:15+00:00

I have a table with 3 columns: userid mac_address count The entries for one

  • 0

I have a table with 3 columns:

userid   mac_address   count

The entries for one user could look like this:

57193   001122334455   42
57193   000C6ED211E6   15
57193   FFFFFFFFFFFF   2

I want to create a view that displays only those MAC’s that are considered “commonly used” for this user. For example, I want to filter out the MAC’s that are used <10% compared to the most used MAC-address for that user. Furthermore I want 1 row per user. This could easily be achieved with a GROUP BY, HAVING & GROUP_CONCAT:

SELECT userid, GROUP_CONCAT(mac_address SEPARATOR ',') AS macs, count
FROM mactable
GROUP BY userid
HAVING count*10 >= MAX(count)

And indeed, the result is as follows:

57193   001122334455,000C6ED211E6   42

However I really don’t want the count-column in my view. But if I take it out of the SELECT statement, I get the following error:

#1054 - Unknown column 'count' in 'having clause'

Is there any way I can perform this operation without being forced to have a nasty count-column in my view? I know I can probably do it using inner queries, but I would like to avoid doing that for performance reasons.

Your help is very much appreciated!

  • 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-23T18:31:16+00:00Added an answer on May 23, 2026 at 6:31 pm

    As HAVING explicitly refers to the column names in the select list, it is not possible what you want.
    However, you can use your select as a subselect to a select that returns only the rows you want to have.

    SELECT a.userid, a.macs
    FROM
    (
        SELECT userid, GROUP_CONCAT(mac_address SEPARATOR ',') AS macs, count
        FROM mactable
        GROUP BY userid
        HAVING count*10 >= MAX(count)
    ) as a
    

    UPDATE:
    Because of a limitation of MySQL this is not possible, although it works in other DBMS like Oracle.
    One solution would be to create a view for the subquery. Another solution seems cleaner:

    CREATE VIEW YOUR_VIEW (userid, macs) AS
    SELECT userid, GROUP_CONCAT(mac_address SEPARATOR ',') AS macs, count
    FROM mactable
    GROUP BY userid
    HAVING count*10 >= MAX(count)
    

    This will declare the view as returning only the columns userid and macs although the underlying SELECT statement returns more columns than those two.
    Although I am not sure, whether the non-DBMS MySQL supports this or not…

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

Sidebar

Related Questions

I have a table with three columns UserID, Count, Date I'd like to be
I have a table with two columns, userID and contentID. Basically this table is
I have a user table with userid and username columns, and both are unique.
I have a table called tblUserLogin. One of the columns is labeled UserID. Evertime
I have a table [Users] with the following columns: INT SmallDateTime Bit Bit [UserId],
I have a table User which has an identity column UserID , now what
i have a database that already has a users table COLUMNS: userID - int
I'm using SQL-Server 2005 Standard. I have Users table with following columns: userID(int), userImage(varchar),
I have complaint table 1. tblProfile with columns userId | name | age |
I have this table where columns correspond to names: i.e. 11 = first, 12

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.