SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sjonkeesse
Starting Member

2 Posts

Posted - 09/27/2012 :  09:38:31  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 09/27/2012 :  09:41:10  Show Profile  Visit webfred's Homepage  Reply with Quote
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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/27/2012 :  09:53:03  Show Profile  Reply with Quote
also

select m.*
from movies m
left join trash t
on t.movies_id = m.id
where t.movies_id is null

select *
from movies 
where id not in (select movies_id from trash)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sjonkeesse
Starting Member

2 Posts

Posted - 09/27/2012 :  10:43:36  Show Profile  Reply with Quote
thank you very much! it's working perfectly!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/27/2012 :  10:45:13  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 09/27/2012 :  10:45:55  Show Profile  Visit webfred's Homepage  Reply with Quote
welcome


Too old to Rock'n'Roll too young to die.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000