Skip to content

Tag: mysql

Find Latest Child Record (With Conditions) Per Parent Record

I have 2 tables with a parent/child hierarchy and am trying to pull the ID for the latest child record for each parent record, but also with conditions applied on the child record that is being pulled. Here’s what my tables look like: Now, let’s say I want to pull ID of latest QuizAttempt for each…

Unknown column ‘r’ in field list

I’ve been working on a SQL query for a project, and I face an error message when I want to use it. Here is the query itself : MySQL answers me “Unknown column ‘r’ in field list”. But I dont really understand why I get an error here as I define r in my INNER JOIN. I’m kinda …

mysql get all table privileges for a user

I have the following query that I run against a postgresql DB whose intent is to return all the tables in a given schema for which the user does NOT have SELECT privileges How would I construct a similar query for use against a mysql database? mysql doesn’t have a has_table_privilege() function Answer T…

SQL Insert into with join and where

I have three tables. For example: newTable: oldTable: associativeTable: What I want to do now is: I want to move the name column from oldTable to newTable. I have already altered newTable and added an empty name column. Now I’m trying to write a correct INSERT INTO statement. What I have so far is: I&#8…