Rajesh Konda
BAN USERThe types of joins I know of are
inner join
outer join
left outer join
right outer join
inner join - join two tables and show only those rows/records where the criteria match.
outer join - join two tables and show all the rows/records regardless of the criteria match. When criteria don't match, column values from left table or the right table would be nulls
left outer join - same as outer join except if criteria don't match, only the columns from the left table will have values.
right outer join - the other way around of left outer join.
Use inner join if criteria match is important for you. Use other join if you want to see all the data.
I think the question is, for each dept, given by name, I want to know how many employees are in that department. As someone suggested above, a dept may not have any employees. In that case, I was to see a '0' against that department. The query would be
Select Dept_Name, Count(*) as NoOfEmpls
from
(
Select E.Emp_ID, D.Dept_ID, D.Dept_Name
from Employees E
rightjoin
Department D
On E.Dept_ID=D.Dept_ID
)
By doing a rightjoin you are ensuring that even if a department doesn't have employees, it would still be counted.
Rajesh
The data structure used doesn't matter unless we know how the function used and how frequently it is used. If the data structure is fixed and the function could be used on any point, then we could think about a data structure that optimizes the computational time.
- Rajesh Konda June 29, 2009The question doesn't specify in which dimension the point is in. If it is an n-dimensional space, perhaps a regular grid of n-dimensional cubes of space could be represented using an n-dimensional array. Each array element or n-tuple uniquely identifies an n-dimensional cube. In one pass, each point could be linked to the corresponding cube. The way the points are linked could be a list or an array. It's easier to build this structure using a list, and it takes less space to store when using an array.
Given a point, the cube in which it exists could be easily identified. Then depending on the distance, one can narrow down the set of points being looked at by narrowing down the surrounding set of cubes.
Further more, if we know the distance D in advance or the range of values for distance D, the n-dimensional cube size could be optimized. Like previously mentioned, 2D is a good size for the dimension of a cube, if D is fixed. That way you make sure that you are atmost looking at 8 surrounding cubes. Given a range, I guess you take the average and use it for D.
Also, in case the number of points is huge, the data could be stored in a distributed network and hence the computation could be optimized, and also parallelized.