Skip to content

Tag: mysql

Check if multiple records exist, with the same id

I am trying to check if multiple records exists with pageId IN(?,?,?) in the chatParticipants table. This is an example of the table structure: This is the SQL query I have tried: Expected behavior: If a conversation already exists, with the given (x) participants, that is, with the same chatId value, then it…

MySQL: Why using where on date column does not use index

I have a table which has a column with type Date which is shown like 2020-06-30 I want to find rows where year of the date column is 2020 in them. The problem is even though its indexed, when I run this: explain select * from table where YEAR(date_c) = 2020; the key and possible_keys are both null. what shoul…

MYSQL Specific Order With Conditionals

Okay… I have three columns that I’d like to order based on their conditions. Column 1 (INT) = last_reboot Column 2 (BOOL) = onlinecheck Column 3 (INT) = drive_use I’d like “last_reboot” to be default and ordered descending. If “onlinecheck” = 0, I’d like it to b…

Unable to join queries

I hope you’re able to help with this, it is creating a lot of unnecessary work for me… I have a lot of users that are assigned a unique session_id each time they start the game. This means they can get multiple session_id ‘s in a single day if they crash and/or just restart the app. I want t…

Append values of other records for a distinct values of a column

if my database table is like: now i want it as: (I need distinct values of name and col-2 values must appended for the each distinct value of name) Both column values are of type text Answer This solved the requirement in MySQL select name, group_concat(col-2) from dbo.sample group by name

How to order a SQL statemnet according to alias name

I have the next SQL statement: I want to order it by FinalTotal, I tried to put : but it doesn’t be affected. how I can sort it? and please note that I tried many solutions on the internet but without result. thanks advanced Answer The fail-safe solution is to place the whole query as a table expression…

check date in create table sql

edit: version 8.0.20 I’m learning sql just now, I try to fix it but I’m not able to do it. I have 3 table This is an easier scheme but it’s enough. The return_date must be less than delivery_date + 30 days I tried to use a check on return_date but no work, so I created a view to select