I have a simple select that returns a single column: result: {1,1,2} I want to check if all result are 1 then return true and if one column have a 2 return false. Tried something like these: But obviously it returns true if a value is 1 and false if it is 2, instead of just one result. For example:
Tag: mysql
Writing a sub-query using a date clause
So basically I’m trying to write something that prints the customer’s name and area code if they have made a booking within the last 6 months of the current date. My code looks like this (it has to be a subquery, not using join) Yet it doesn’t work, but I can get it to work using a join func…
Using left join to query and match JSON field in MySQL
Table A,field : pay_type_fk,type:json, Examples Data: [1,2,4] Table B,field : id type : bigint Examples Data: primary key SQL I use: Only pay can be found_ For the first record in the type table, I think we can query all of them with group_ CONCAT Answer If I follow you correctly, you can join on JSON_CONTAIN…
MySQL query to update players weekly ranking positions with large dataset [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I’m trying to update weekly ranking scores for players, but any query I have tried jus…
Search function on multiple rows in the same table
I’m wondering how do I add more row’s on my search script to be searched. Here’s my php script: As you can see this: I want to it to search on region and rank rows. I tried: …. it’s showing 0 results. Thank you in advance. Answer Is this what you want? This searches for the param…
Update column value based on ORDER of another query
What I have: Hi guys, I have two tables. #1 model Where I store all models #2 video_models_model which connect model and video table (video is unrelated now) until now always when I needed models I ordered them based on in how many videos they are used in What I need: However I found out that sometimes I need…
How to replace table1 column value with table2 column value in MySQL select left join
Let’s say I have two MySQL tables: table1 (templates) Columns: id_template, name, col3, col4, … table2 (aliases) Columns: id_alias, id_template_orig, id_user, alias I want to select a row from the table1 (templates) including all the columns (*). In the same select statement I want to check if cur…
COUNT WHERE two conditions are met in the same column
I’m sure this has been asked before, but I can’t find a similar situation: Given a table ‘activity’ I need to count all users that have ‘SEM’ AND at least another channel IN contact_channel_ID Answer You can use aggregation and having: In MySQL, the having clause can be sho…
how to calculate the previous total with the current total with group by
I need to calculate every month with the previous months like: for each account. so how can I do it, I tried to extract the totals by each month but I didn’t get any result. DDLs: example of my data for the specified user is: this is the result that gives me: what I need now is: how to calculate
MYSQL subquery results columns not as expected
I am trying to build a query that will build a output like this. The output that I go is this I was following the instructions here https://www.mysqltutorial.org/mysql-subquery/ My query is this What I was expecting to happen was the alias ‘patient appt’ to be populated with the data from the nest…