SQL inner join and counting query?
How do I join 3 tables and display all the columns by using INNER JOIN and ON?
How do I count the number of employees in a table where the employee does not have a middle initial? How do I write this condition?
Can anyone help me with the syntax? I wrote different queries and always got syntax errors for them.
Thanks.
1. select * from TableA
inner join TableB
on a.Field = b.Field and a.Field2 = b.Field2
inner join TableC
on b.FieldC = c.FieldC
GO
2. Select count(*) from Employees
where isnull(MiddleInitial,”) = ”
GO
For multi-table inner joins, I prefer just using appropriate WHERE clauses as they are (IMO) less confusing (plus you have better control over the order the joins are done which can make the queries process more efficiently).
SELECT some fields FROM first_table a, second_table b, third_table c
WHERE a.matching_field = b.matching_field
AND b.matching_field = c.matching_field
To do the count, it depends on how you indicate a ‘missing’ middle initial – I would imagine it is either marked NULL or set to spaces.
SELECT count(*) FROM someTable
WHERE middleInitial IS NULL
or
SELECT count(*) FROM someTable
WHERE middleInitial = ‘ ‘
References :
try read this free ebook:
http://hugebook.net/?p=248
References :
1. select * from TableA
inner join TableB
on a.Field = b.Field and a.Field2 = b.Field2
inner join TableC
on b.FieldC = c.FieldC
GO
2. Select count(*) from Employees
where isnull(MiddleInitial,”) = ”
GO
References :
–I do this for a living