Skip to content

Tag: mysql

How can I combine two columns and sort the values alphabetically?

I’m new to programming languages and am trying to get the customers with the longest and shortest names, combine them in a single column, and sort them by longest then shortest names. Here’s what I have. How can I query to get my desired result in MySQL? Table is orders customer_id longest lowest John N…

Is it possible to further filter on MAX results?

I have a table like so A) As you can see, the same ID can have multiple Revision IDs Now, I can grab all the latest revision for each ID by using MAX with GROUP BY like so: B) As you can see here, the Revision ID of 47141 is the latest revision for ID 3282 So here is my

MySQL – Join 2 tables and count number of entries

I’m trying to join 2 tables and count the number of entries for unique variables in one of the columns. In this case I’m trying to join 2 tables – patients and trials (patients has a FK to trials) and count the number of patients that show up in each trial. This is the code i have so far: Th…

Alter Table Foreign Key

I’m trying to add barista_grade_id to the baristas table as a foreign key and I’ve looked every where on what syntax to use and it seems to be unanimous that this is the correct way. I did it before this and it worked. but because of some mistakes I deleted it and redo it again, but for whatever r…

How to return multiple rows in stored procedure?

I have a procedure that returns multiple rows, but separately. Please take a look at its result: I causes some issues when I want to fetch the result in the code (backend side). Now I want to create a temporary table and insert all rows inside it and then return that temp table as the result of the stored pro…

Time difference between start/stop interactions

I have two tables in my database that looks like this learner_lessons learner_lesson_logs Basically, when a user clicks on a video it starts playing and the interaction is recorded as ‘Start’ and a timestamp is created accordingly. Now when a user pauses the video another interaction ‘Pause&…