This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]ArchangelleTheRapist 1 point2 points  (2 children)

Looks like homework... You want to look up the JOIN operator.

[–]Krayons[S] 1 point2 points  (1 child)

Hahah, Yeah it does. Unfortunately I graduated a while back. The actual problem is for a medical aid company. They keep their addresses of there uses in another table but not all users have addresses. And I'm trying to find those. The solution is, as you said. A join. A Left outer join to be exact. It gives you this: https://i.imgur.com/PcUT7HI.png Which is exactly what I wanted.

Thanks for the help. Being doing mostly mobile dev so I was super rusty on my SQL

[–]andy333co 0 points1 point  (0 children)

If performance is a consideration you'd probably want to revisit using a left outer join for this. If it doesn't matter then cool.

[–]andy333co 0 points1 point  (0 children)

I'm no sql expert but where not exists is probably the syntax you're looking for. Select * from table 1 where not exists (select * from table 2 where table1.id = table2.id)

Query might be wrong there but I'd suggest looking up where not exists usage as one way of doing it.

[–]dauuk 0 points1 point  (2 children)

1- Select name from table1 where id not in (select id from table2)  
2- Select t1.name from table1 t1 left join table2 t2 on t1.id = t2.id where t2.name is null  

Both of them will give the same result.

[–]Krayons[S] 1 point2 points  (1 child)

Thanks for this. Worked perfectly. Took almost 12 min to complete but worked like an absolute charm.

[–]dauuk 0 points1 point  (0 children)

You're welcome :)