(I’m using mysql v5.7) I have a csv file that has something like mytable1 note that ‘aaa,bbb,ccc’ is one string and ‘8,3,5’ is one string.. I know it’s not a good practice putting data like this but this is what I have given from other department… so my first task was…
Tag: mysql
MySQL (Percona) Error 1452: Cannot add or update a child row for no reason
I have 2 Database Tables “users” and “tasks”. The tasks table contains two foreign keys for the createdBy_user_id and updatedBy_user_id columns both referencing users.id. If I try to insert an entry to tasks (after making sure the user referenced by the foreign keys exists) like this: …
Compare values of timestamps and assign a value to each of them in case they have changed
DB-Fiddle Expected Result: In the above result I want to list all products from the table and compare the two time_stamps to each other. If the plan_week of one product has switched between the both time_stamps I want that in the additional column called week_switch the word yes gets inserted and if not the w…
SQL table primary key’s index is starting at 3
I set the column Id to the primary key and set it to increment but its starting at 3 for some reason. I will post a picture below: Sql table not incrementing correctly
what does this hyphen do between columns in order by clause in mysql query?
what does this hyphen do between updated_at and created_at columns in order by clause ? select * from `users` order by updated_at – created_at DESC
Reuse select aliases in MySQL
I currently have a query where I’m doing two subqueries to get X, Y data: Y is kind of subset of X, since I apply just an additional condition to the existing ones, if X is: Then Y has an additional AND condition: And for the value of X I need to take those two results – X and Y
Count of values grouped by a row id
My data looks like the below, I want to sum up the count of occurrences of ALL. This should be grouped by Id. So the output should look like, My query looks like, This query is giving me the result as, which is incorrect for Id 2. The value for Friday for the second row is an empty string. dbfiddle
Split value into multiple rows
The following are two tables I have in the database mavenmovies. testLocation (TABLE 1) CREATE TABLE mavenmovies.testLocation ( id INT AUTO_INCREMENT PRIMARY KEY, State varchar(255), name …
Auto increment temporary column in select statement MySQL 8
Hello i use this type of sentence to return an auto increment column in my prepared statement selects cnt := cnt + 1 SET @query = CONCAT(‘SELECT * FROM (SELECT (@cnt := @cnt + 1) AS id, a….
Create an insert to pivot value pair values into a table
I have a value pair table that I want to use to create a member table Based on Taryns answer to this question MySQL pivot table query with dynamic columns I have this code that creates selects the …