I have two tables that look something along the lines of: And a query to get data from t1. The query runs fine and takes a few ms to get data from it, although problems start appearing when I use joins. Here’s an example of one of my queries: Which can return a few thousand rows, that might look somethi…
Tag: mysql
Aggregate function MAX giving unexpected output when used inside a HAVING clause
The Table Id Salary 1 100 2 200 3 300 I want to find out all the salaries lesser the highest salary. For doing so, i have come up with the following query- Which yields the output- {“headers”: [“salary”], “values”: [[100]]} But my expected output here is {“headersR…
MySQL Convert alphabet to number (e.g ‘A’ to 1, ‘B’ to 2…)
I’m making mysql SP, which has an input of type VARCHAR(20). What I want to do is to convert the last character of input string to a number. However last character can be number or letter, so if it is number, converting is not needed. For example, input ‘APPLE’ will be converted to ‘5&…
Count from 4 tables with join and null values
Tables: What I am expecting to query is this: However this is what I get: With this query: I wonder, in what way the query above could be modified to return the expected results? What would be a good approach to achieve this? Answer You are joining along two dimensions, so you are getting a Cartesian products…
SQL select query retrieval blank return
I have to retrieve distinct entities from a column, all of which start with a vowel. The query looks like this : It’s not giving compilation errors, but it’s not returning anything. Any ideas? Answer You can use regular expressions: LIKE wildcard patterns do not support character classes, except i…
How can you group data by multiple fields with separate totals in SQL or Power query
I have a set of data that I want to count by multiple characteristics. I am starting with something likes this (True/False for catagories) week PP SEN 1 T F 1 T T 1 F F 2 T F 2 T T 2 F F 2 F F 3 T F 3 F F I want to end up with
Weird behavior of MySQL Server when ordering by 2 conditions
Say a database table my_table has the following structure: and some of the rows in the database have total_votes == 0. I want to get the rows ordered like this, except I also want to include the rows that have total_votes == 0. I tried using the following query, and it worked like a charm: My question is why …
How to left join when only matched one record from right table
I want to know How to left join when only matched one record from right table. For example, tableA id value 1 34 2 42 3 60 tableB id value tableA_id 1 20 1 2 31 1 3 50 2 I want to get result like below using left outer join. tableA_id tableA_value tableB_value 1 34 null 2 42 50
i have birthdate in the table , i need to find age between 30 to 70 how can I write sql query for that? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 months ago. Improve this question begin age and end age find where age is between 30 to 70 i just have bir…
If a meta_key has a meta_value, update the meta_key name
In a table called wp_postmeta, there are ~1K meta_key’s called _wcj_custom_product_tabs_content_local_1, but only ~100 have a meta_value. What I need to do is update the meta_key name, but only for the meta_key’s that actually have a meta_value. I can select all the meta_key’s that are not e…