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…
Tag: mysql
Compute 2 Columns from current row and from the row above
I have a table that looks like this My target is to look like this Basically what it did is to sum all the way down based on stock in and stock out from beginning balance however I cant achieve it. …
case and order by – How to specify that something should be shown in the end of the list?
From: https://www.w3resource.com/sql-exercises/sql-retrieve-exercise-24.php Write a SQL query to find all the details of 1970 winners by the ordered to subject and winner name; but the list contain …
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…
Subtract a number from the rows until the number ends to zero
How can subtract a number from the rows to the end of the subtraction in MySQL with query update If have table like this and i want subtract “80” form qoh to get the output I tried by and not work What is the appropriate adjustment to do? Answer If you are running MySQL 8.0, you can do the computa…
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