Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 7 months ago. Improve this question I ha…
Tag: mysql
Generate two SUM value columns for two different dates separately in one query
I am trying to combine two queries . and I want it so there is one table with one column for s.id and the next columns are VAL columns for each respective date. Where a value is not available for a give s.id on a specific date it should show NA. Answer I supppose you are looking for conditional aggregation
Using parent SQL column in subquery
Good morning. I’m trying to pull the username of the user from the column in to_id. Is there. It’d be simple if I was just filtering on to_id, but I also need records from another column from_id. I’ve attempted doing a UNION to get around this issue, but it only pulls records from user.id 3 …
Trying to get the 2 min(count()) with Ties
I allow myself to write a thread regarding a query I’m trying to make for hours now. I’m trying to get the name of the friend (friend.first_name) who refuses the most proposed dates for events. To do this I’m counting the number of proposed date and ORDER BY ASC. However, this does not take …
php stop sql query from running every time on refresh
In my php script, I used a sql query to create a table, but after creating the table every subsequent refresh will return an error message stating table is already created. I know its already created but how do I stop query from running a second time on refresh if its already ran? php script: Answer The DDL c…
Take maximum time during update left join mysql
I am doing an update left join on ID and receiver. How can I make the query to pick the record with max time taken? Expected output : Answer I have added another column (id_primary) in right_table. To get the maximum use this subquery (select id_primary from right_table order by time_taken desc limit 1) at en…
How can I concatenate field values together from other records in same table?
I have a simple table as below in MySQL. All I want to do is group records by PARENT ID and concatenate ATTRIBUTE records for that PARENT ID into the TYPE=’SIMPLE’ record. UNIQUE ID TYPE Parent ID Attribute MYID1 SIMPLE MYID1 MYID2 VARIANT MYID1 WHITE MYID3 VARIANT MYID1 BLUE So the result would b…
UPDATE RECORD 2 FIRST LATTER IN MYSQL [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 11 months ago. Improve this question How…
Mysql where condition for single SELECT [not all]
I want to calculate the total gross amount of a CLIENT in all stores and in a specific store both in one query. Not repeating the same query twice as I did below and also not using group_by. My tables are: Clients and Orders Expected result: My query is Answer SUM with CASE WHEN for given store to get gross
MySql view with group_by very slow
I have two tables, appointments and clients. The tables are big, each with about 100M records. each has a primary key on id clients has a foreign key on appointment_id I’m using mysql 5.7 As one would expect, the following query is lightning fast: But, if I create the following view and query, it is int…