SQL Query Help needed!

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 21
Reputation: newMeg is an unknown quantity at this point 
Solved Threads: 0
newMeg newMeg is offline Offline
Newbie Poster

SQL Query Help needed!

 
0
  #1
Aug 24th, 2008
Hi,
I need help on this sql. I have a table a and b and i need to select where a.id=b.id and b.mid=1 and few hardcoded a.id which does't exist in table b. i used left outer join but its still listing all in a table. Can anyone help pls.

Thank you
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: SQL Query Help needed!

 
0
  #2
Aug 24th, 2008
you need to do an inner join if you are not wanting to list all in the tables that share the record ids.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 21
Reputation: newMeg is an unknown quantity at this point 
Solved Threads: 0
newMeg newMeg is offline Offline
Newbie Poster

Re: SQL Query Help needed!

 
0
  #3
Aug 24th, 2008
Originally Posted by dickersonka View Post
you need to do an inner join if you are not wanting to list all in the tables that share the record ids.
Hi, Thanks for the reply. I did an inner join and i'm still not getting the result. Nothing is queried out because of the c.CreatedBy = '2418' which doesnt exist for the identifier ('1','2','3','4','5','6').

This is the inner join sql:

  1. SELECT *
  2. FROM TBL_ComponentList c INNER JOIN TBL_Modules m
  3. ON m.Identifier=c.CompIdentifierID AND c.CreatedBy = '2418' AND m.identifier IN ('1','2','3','4','5','6')


If i do it as 2 separate sql, i get what i need but i need to make it as 1. The 2 sql that i need to join is


  1.  
  2. 1) SELECT * FROM TBL_Modules WHERE identifier IN ('1','2','3','4','5','6') ORDER BY Identifier
  3. 2) SELECT * FROM TBL_Modules m,TBL_ComponentList c WHERE m.Identifier=c.CompIdentifierID AND c.CreatedBy = '2418' ORDER BY m.Identifier

the identifier id 1 to 6 doesnt exist in table componentlist.

Any help pls?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: SQL Query Help needed!

 
0
  #4
Aug 25th, 2008
You said in the first you wanted a.id=b.id,
what are the columns for a.id and b.id?

But are you saying that a.id might not exist?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 42
Reputation: huangzhi is an unknown quantity at this point 
Solved Threads: 13
huangzhi huangzhi is offline Offline
Light Poster

Re: SQL Query Help needed!

 
0
  #5
Aug 26th, 2008
You can combine your 2 query with 'UNION ALL' or 'UNION' like below:
  1. SELECT * FROM TBL_Modules WHERE identifier IN ('1','2','3','4','5','6') ORDER BY Identifier
  2. union ALL
  3. SELECT m.* FROM TBL_Modules m,TBL_ComponentList c WHERE m.Identifier=c.CompIdentifierID AND c.CreatedBy = '2418' ORDER BY m.Identifier
Hence Wijaya
www.ex-Soft.tk
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC