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…
Tag: mysql
Order results by “Best Match” SQL
I’m working on a project which requires the user to search for certain categories of products. The products have tags such as: T-shirt, Jumper, hat and I am currently displaying the results ordered by the amount of likes. Here’s my SQL statement: But the issue is that if let’s say someone se…
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 …
query to get customer list using JOIN with sum () of the amounts spent in orders
I have the following tables table anag (customer registry) table levels (table that connects each customer to his salesperson. For database registration reasons, the link between customer and seller is given by the customer’s telephone number) table orders (contains all purchases made by customers, of c…
MYSQL joins and then making queries on the joined table
I am trying to do a join on a database and subsequent queries, in this database which is a dummy one from MYSQL y hace these tables and in the salaries table i have something like these So I am trying to sum the salary and group the result by employee number so I have just one value per number,
MySQL – category with product count not showing all results
I am trying to display the count of products along with the category name in the category list. I was able to achieve this with JOIN, but not all categories are displayed. I mean the categories with 0 products were not displayed, but I changed the JOIN to LEFT JOIN which displayed only one category with 0 pro…
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…
I have a double relation of the id of one table to another table and I need to build a relation with the same id in another table twice
I have this table id subOperation 1 test1 2 test2 3 test3 4 test1,test2 5 test1,test3 I need help, to make a query which gives me the following result id idSubOperation idElement 1 1 1 2 2 2 3 3 3 4 4 1 5 4 2 6 5 1 7 5 3 When I have one “,” I need
Joining two tables with same keys but different fields
I have two tables both all with the same fields Except for one. I want to combine these two tables with the resulting table having all the fields from both including the two fields that are not the same in each table. I.e: lets say I have table order_debit with schema and table order_credit with schema What I…
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…