Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SQL question - the missing ID

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

quick question:

SELECT ID, COUNT(ID)+1 AS numFamily FROM tableA Group By ID

the result for this query will be somthing like:

105 4
106 8
107 3
109 4

the problem is (and this is my question) what if ID=108 is not mention in this table (it exist but in a different table) how can I get a result where:

105 4
106 8
107 3
108 1 //<-- added this (the num one is there becuase I COUNT(ID)+1 )
109 4


thanks for any help
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
Use a "union". Look it up in the documentation for the database you are using.

Good Luck,
Avi.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!