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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:45:15+00:00 2026-06-01T23:45:15+00:00

Here is my query: SELECT v2.mac, v2.userag_hash, v2.area, count(*), count(distinct v2.video_id) FROM video v2

  • 0

Here is my query:

SELECT v2.mac, v2.userag_hash, v2.area, count(*), count(distinct v2.video_id) 
FROM video v2 JOIN (
  SELECT distinct v.mac, v.userag_hash 
  from video v 
  WHERE v.date_pl >= '2012-01-30 00:00' AND 
    v.date_pl <= '2012-02-05 23:55' 
  ORDER BY rand() LIMIT 50
) table2 
ON v2.mac = table2.mac AND 
  v2.userag_hash = table2.userag_hash AND 
  v2.date_pl >= '2012-01-30 00:00' AND 
  v2.date_pl <= '2012-02-05 23:55' 
GROUP BY v2.mac, v2.userag_hash

I have one table “video” in the database, it contains several thousand users’ data, now I want to randomly select 50 users and calculate based on the selected rows, (each user is identified by unique combination of ), this query’s result is:

 usermac1, userag_hash1, area1, 10, 5
 usermac2, userag_hash2, area2, 20, 8
  ...

But if I don’t use “GROUP BY” in the end of the query, then it will return only one row:
usermac, userag_hash, areax, 1500, 700 (don’t know what this row stands for)

I am wondering if the “1500, 700” is the sum of the last two columns of the previous results. like 1500 = 10+20+… 700 = 5+8+…

  • 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-01T23:45:16+00:00Added an answer on June 1, 2026 at 11:45 pm

    Based on the fact that you have only one aggregate function (count) and used on 2 columns, and you can run it without GROUP BY at all, you must be using the non-standards compliant MySQL.

    SELECT v2.mac, v2.userag_hash, v2.area, count(*), count(distinct v2.video_id) 
    ...
    

    Whatever your data is, MySQL will return one row when you use aggregate functions, which is:

    <undefined value>, <undefined value>, count of all rows, count of rows where v2.video_id is distinct (and probably non null).
    

    So I think you have 1500 rows, and 700 distinct values of v2.video_id, or 700 non-null distinct values. To test this null idea, try:

    count(distinct IFNULL(v2.video_id,'nullvaluehere'))
    

    which will convert nulls to non-null so they will be included.

    The “undefined values” could be the first row, last row, first where something is non null, first in an index, first in some cache, etc. There is no definition of what should happen when you write an invalid query.

    Every SQL database I’m aware of other than MySQL will give you an error message and not even run the query. For the query to be valid, it must have all non-aggregated columns in the group by. eg. mac and userag_hash must both be in group by.

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

Sidebar

Related Questions

Here is my query: SELECT DISTINCT `c`.`user_id`, `c`.`created_at`, `c`.`body`, (SELECT COUNT(*) FROM profiles_comments c2
Here is my query select t1.*, t2.name as customer, t2.name as vendor from order
Here is my query select * from table1 inner join table2 on table1.typeId=table2.typeId; This
Here is my query: select s.*, u.display_name from wp_wdify_sites s, wp_users u LEFT JOIN
here is query SELECT `mpv`.`member_id` as member_id, `screen_name`, `viewed_url`, count(viewed_url) as viewed_url_cnt FROM (`tracker`
Here is my query: SELECT dbo.EmailCampaignTracking.emailOpened, dbo.EmailCampaignTracking.emailUnsubscribed, dbo.EmailCampaignTracking.emailBounced, COUNT(*) FROM dbo.EmailCampaignTracking Group By dbo.EmailCampaignTracking.emailBounced,
Here's my query: SELECT * FROM designs AS d LEFT JOIN categories AS c
Got this here query: EXPLAIN SELECT persons.id AS id, ppm.first FROM myschema.persons INNER JOIN
Here is my query: SELECT * FROM [GeoName] WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005 ORDER BY
Here is my query: SELECT count(*) FROM table_testcase_execution WHERE campaign_session_id = any(SELECT campaign_session_id FROM

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.