Skip to content

Tag: join

How to LEFT JOIN with multiple cases

Assuming I have these two tables like: Table: tab1 valA valB valC valD 1 11 111 A 2 11 333 A 3 44 444 B 3 66 666 D Table: tab2 val1 val2 val3 val4 1 11 111 A 1 22 222 A 2 44 333 B 3 55 555 A 3 66 666 D I have 3 cases that

LEFT Join on a Subquery with specific criteria

I have two tables that I am trying to JOIN I am attempting to Select from table1 a and LEFT JOIN table2 b on a.id = b.id – however, I want to only select on the id in table2 where MAX(EndDt) Is something like that doable? Answer There are a few ways you can do this. I make some assumptions

Join mysql table with distinct value from another table

I encountered a problem on a database I am working with. I have a table of counsels which may hold repeating values, but their is an enrolment number filed which is unique and can be used to fetch them. However, I want to join from a cases_counsel table on the “first” unique value of the counsel t…

Join tables together

I need to write a SQL statement to find the ‘Action’ (category) films with the shortest running time (length). Your query should output the titles and lengths of the films. This is the database schema I have. I created 3 tables and inserted some records on these tables. I write my query like this: But there a…

How to copy data from one column to another?

I am trying to add Property Address in columns that have a missing value. I use the below to identify common parcel IDs with corresponding property address since the same parcelIDs have the same PropertyAddress as well. I get this result: Now I want to add the data in column IFNULL(n.PropertyAddress,n2.Proper…