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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:27:46+00:00 2026-06-11T07:27:46+00:00

I have MySQL table with structure: | uid | itemid | ——————- | 1001

  • 0

I have MySQL table with structure:

| uid     |   itemid
| -------------------
| 1001    |   9999
| 1001    |   8888
| 2002    |   8888
| ...     |   ...

uid and itemid not unique columns. Bun uid+itemid is unique combination.

I need count rows by itemid. I use next query:

SELECT itemid, COUNT(*) 
FROM unlikes 
WHERE itemid IN ('9999', '8888') GROUP BY itemid;

And this works!

Next, i need to know which row have concrete uid. I use:

SELECT itemid, COUNT(*), IF (uid = '1001', TRUE, FALSE) toggled 
FROM unlikes 
WHERE itemid IN ('9999', '8888') GROUP BY itemid;'

Not work. If i have more than one row with itemid = 8888, than toggled = FALSE. I need toggled = TRUE if one in group have uid = 1001;

  • 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-11T07:27:48+00:00Added an answer on June 11, 2026 at 7:27 am
    SELECT itemid, COUNT(*), 
    CASE WHEN uid = 1001 THEN TRUE ELSE FALSE end AS toggled 
    FROM unlikes 
    WHERE itemid IN ('9999', '8888') GROUP BY itemid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have following table structure in Mysql DB Table: Mytable -------------------------------- | uid |
I have a MySQL database table with this structure: table id INT NOT NULL
This is the MySQL table structure that I have: itemID (BIGINT) userID (BIGINT) wasAdded
I have a mysql table structure like that: id int primary key name varchar
I have the following MySQL table structure: num field company phone website 1 Gas
I have a MySQL table with a structure like the following: I'm looking for
I have a MySQL table with the structure: beverages_log(id, users_id, beverages_id, timestamp) I'm trying
I have a MySQL table with a tree data structure. The fields are _id
I have a mysql database with a table structure like below : Table Name

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.