Skip to content
Advertisement

Tag: mysql

How to count active users using mysql

I’m trying to count active users in the last month by comparing the logged event against today’s date. So for example if a user logged in 2 days ago(09/01/2021), the query would evaluate to true since the logged in month 9 = todays month 9 AND logged year 2021 = todays year 2021. since its only using months and years,

Mysql duplicate results of query relation with 2 other table , IN operator

I have 3 main table : products, stores and categories product relate many-to-many with stores via table product_store product relate many-to-many with categories via table product_category How can i query all products, belongs a store ( with store_id : 1 ) and belongs one or many category ( with category_id in [ 4,5,6 ] ? I used below syntax, but

MYSQL joining two table slow

I have 2 main table in MYSQL DB. I will call it entityA and entityB. There are some logic that user will start to create a entityA and then convert it to entityB but some time they will not create entityA and only create entityB Therefore, I have created a middle table which stored entityAId and entityBId. entityAId entityBId 1

Single table or multiples tables (multiple company database)

I have to create a database for multiple companies, I have 2 options A single products table, with a company_id field to differentiate One table per company products_company1 products_company2 products_company3 Important: Data stored of each client will be updated every 1 hour Each company has 2000 – 3000 records, and 15 company will be stored approx. Products table is an

phpmyadmin how can i create a event like this?

I am creating an event on one of my databases to check if the client changed a specific parameter called ‘serverlog’ which is a boolean on my Sql database. Is there a way to loop through all the users in a table called ‘users’, check if ‘serverlog’ is false and update/set a different parameter called ‘islogged’ in the user table.

Subquery to get derived value

I have the below table T in MySQL, with columns A and B. I want to query this table to get a value ‘C’, that has the count of the number of times the value in Column ‘A’ appears in Column ‘B’. For example, 1 appears 2 times in Column B, so the first row of column C should be

Why are my counts different when using CASE operator VS IF function?

I learnt that the difference between CASE and IF statement is as follows “IF is a CASE with only one ‘WHEN’ statement”. But I got confused when querying this: I have the table Olympics which contains the countries and medals associated to it. I am counting the total number of medals won by each country. The first query results in

SQL get most recent joined record

I’ve the following tables: chat: chatId, jobId chat_message: userId, chatId, message, created_at chat_user: chatId, userId Am trying to get the last message sent by a specific user for all chats he’s a part of. This is what I have so far (left join for debugging on null): The problem with this query is that the LIMIT 1 makes chat_message results

Advertisement