Skip to content
Advertisement

SQL Query to determine number of tables

I have this table and I’m trying to determine how many Tables (in a restaurant) are awaiting food. The table( in the database) has the following columns: TableNumber, ObjectType, ObjectDescription and Quantity (amongst others).

I made this query to see what is ordered, but would like to know how many unique tables are waiting for food…..

which gives me the following output…

I tried to use count and distinct in the query but nothing I tried seems to give me an extra output for the unique number of tables(restaurant) which should be 5 in the above result.

Can anyone help me? Grateful in advance!

Advertisement

Answer

To add a column which contains the (repeated) [### OF TABLES] you could use CROSS JOIN

[Edit] Without the CTE to work in SQL 2000

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement