Skip to content

Tag: join

Postgres LEFT JOIN not returning nulls?

Not sure why this is happening, but I have this query: And the item table has 100 elements. I’m looking for the resulting rows to be grouped by user_id and have each array be 100 items long. That is, if the value is not present in the vote table, to just instead sub in a 0 in its place. Unfortunately

How to use join to link values from one table to another

I have two tables. drivers name number email requests id driverassigned …. I want to get everything from drivers table that may or may not be mentioned in requests.driverassigned. I have tried using join but it returns rows that have a match. Here is what I have so far. I am sure there is a common solut…

Merge two tables in SQL, with one common column

I’m trying to merge to tables in MSSQL, as in the sample below. My situation is similiar to this question. T-SQL merging two tables with common and uncommon columns I have tried using the following query: But it results in this, where the rows that have the same value in column a, merges in the same row…

SQL selecting most recent row inside join

I have 2 tables companies and invoices I want to select all companies with their most recent invoice price. I don’t seem to get it working. This is what I tried: But the query loads very long and I don’t know why. The structure looks like this: companies invoices The BC_ID is the same as the compa…

Replace subquery with join for the same table

Can the expected result in this case be accomplished without a subquery ? Maybe using a join ? We have a name say ‘jose’, Expected result is all rows which has same color as jose. Query should run in both MS-SQL and ORACLE. http://sqlfiddle.com/#!18/5f7e3/2 Answer You can get this result with a JO…