Skip to content

Tag: mysql

MySQL Group By for sorted table

I’ve two tables with these structures: Table 1 (comments) Table 2 (posts) My goal is to get a list with the latest comment from each post of a specific category_id. So for example, if I have category 1 as input I need the comments with the id 2 and 1 because these are always the last comments for each p…

Mysql Left join index

I used the following query To display items from two tables, where the id of the first table is the item_id of the second. My question is , when I try to display this in php , if I want to display a.id i can try with: or since both tables have id,on the first example displays only if there

Only display values of latest available event type

SQL Fiddle: In the table above the purchasing process for different campaigns is displayed using an Event_Type and a Quantity that applies to the Event_Type. Every campaign can only have each Event_Type once. Now, I want ot get the Quantity of the latest available status within the purchasing process for each…

Laravel 6 many to many relationship

In laravel 6, I have 2 models I have third model to join tables Now how can I get all the teachers those are not subscribed by a particular student? For example: Teacher1, Teacher2, Teacher3, Teacher4 are in the Teacher table and Student1, Student2, Student3, Student4 are in the Student table Student1 subscri…

Copy result of select statement into a local database table

I would like to copy the contents of a remote DB query into a local database table. What would be the best way to do this? Currently I’m trying something like: The first part of the command works fine to grab the data — the second part I’ve just added as a sort of pseudo-code to show what I&…

MySQL select complete last month

How to select all data from last month (or 30 days)? I already found some answers, and mostly gives this solution But this gives me also the dates from the future I am only interested in the days from last month or 30 days (not next month and beyond) Answer Is this what you want? I added a condition so

mySQL Self Join – inner join or join

quick clarification. When joining contents from the same table, must I always declare join type as INNER? For example, (on the table shown in this screenshot) When I tried to remove the keyword INNER, it was wrong. Is it because JOIN does not exist in SQL? Thanks and cheers. Answer You do want a self (inner) …