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

3 Responses to “SQL inner join and counting query?”

  1. TheMadProfessor on November 29th, 2009 at 9:38 am

    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 :

  2. try read this free ebook:

    http://hugebook.net/?p=248
    References :

  3. Solly Wolly Doodle NOR♦CAL R&S on November 29th, 2009 at 10:51 am

    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

Leave a Reply