I have an MySQL InnoDB table with 5.7M rows and 1.9GB size: +——————-+———+——+—–+———+—————-+ | Field | Type | Null | Key | Default | Extra …
Tag: mysql
Query slow when use count(*) and inner join
My query is taking around 5 seconds to run. It returns almost 5000 records. If I remove the Select Count(*) …, it runs very fast, but I need this data. Is there a way to improve this query? Thanks Answer Indexes recommended by Gordon Linoff are a must-have. Another thing you could to is move the computa…
Summing the total of 4 alias
I have the following query: SELECT SUM(case when s1 = ‘fel’ then 1 else 0 end) as s1_count, SUM(case when s2 = ‘fel’ then 1 else 0 end) as s2_count, SUM(case when s3 = ‘fel’ then 1 else 0 …
MySQL selecting entries when true and replace with null when false
I am programming an office schedule. I have a table users in which each user has a regular schedule hreg that is monday to friday. I have a table hleave in which I enter a leave code for the dates …
SQL Query Sum, Multiply and combine 5 tables then group
I’ve created my table. I’m trying to craate a query that multiply and add sold_quantity from sold table and sale_price from on_sale table and called it R1 for now, and retail_price from product table …
sql – Is there a way to filter through the results of a SELECT query, with another SELECT query?
Specifically, what I am trying to do is rank a table by a column value, referred here as power, and then take that ranked table and find a specific row, or a user in this case. Much like what would be …
Get column name of Table based on query
I have this SQL query Query And this is my table let’s say Tree_table So I want my output to be Is this possible using SQL query or even PHP will do Answer You need to unpivot the data. In MySQL, this is probably most easily done with union all:
sql – group by using dynamically selected table names
I have a table called app_to_tables which is mapping between apps and table names, table names are around 20, so I cannot hard code them in the query. Here for simplicity I put just 2 table names (…
Is there a better way to simplify many nested select statements?
I am worried that I think about SQL wrongly. I am able to hack queries together to do what I want, but they end up quite ludicrous with multiple nested selects. Here is an example that I can’t fathom …
Select column as true / false if the keypair exists in another table
I have currently these tables. Server: MariaDB (I removed some columns to make it more simple) Person table: id | username | password ——————————————-…