Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sjonkeesse
Starting Member
2 Posts |
Posted - 2012-09-27 : 09:38:31
|
Hi, I am trying to make a query for my new project.I have 2 tables in my database and I need only results from 1 table.The first table is calles `movies`. The second one `trash`.I need the rows of `movies` exept where the `movies`.`id` equals `trash`.`movies_id`.I have tried this query:SELECT * FROM `movies`, `trash` WHERE `movies`.`id` != `trash`.`movies_id` (also with GROUP BY `movies`.`movies_id)But this query is not working. Im getting a lot of results but also the movies that are in the `trash` table.Also I have search on the internet for a solution but I don't know exactly where to search for.Is there someone who knows the answere?Thanks anyway! |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-27 : 09:41:10
|
select * from movies m where not exists(select * from trash t where t.movies_id = m.id) Too old to Rock'n'Roll too young to die. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-27 : 09:53:03
|
alsoselect m.*from movies mleft join trash ton t.movies_id = m.idwhere t.movies_id is nullselect *from movies where id not in (select movies_id from trash) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
sjonkeesse
Starting Member
2 Posts |
Posted - 2012-09-27 : 10:43:36
|
thank you very much! it's working perfectly! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-27 : 10:45:13
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-27 : 10:45:55
|
welcome Too old to Rock'n'Roll too young to die. |
|
|
|
|
|