cee4
cee4

Reputation: 17

Taking away a column in TSQL

SELECT VendorName, COUNT(*) as Total_Invoices
FROM   Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE  Vendors.VendorName = 'IBM'
GROUP BY VendorName
ORDER BY Total_Invoices DESC

It will bring up

VendorName  Total_Invoices
IBM                2

I want to make it so it just says

Total_Invoices
     2

without the IBM VendorName being shown but still counting the Total Invoices from IBM

Upvotes: 0

Views: 92

Answers (3)

András Ottó
András Ottó

Reputation: 7695

You just have to clear the VendorName from the Select. And you don't need to use GROUP BY or ORDER BY in this case

SELECT COUNT(*) as Total_Invoices
FROM   Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE  Vendors.VendorName = 'IBM'

Upvotes: 3

RonaldBarzell
RonaldBarzell

Reputation: 3830

Remove VendorName from SELECT.

Upvotes: 1

John Woo
John Woo

Reputation: 263703

you can safely remove VendorName on this case.

SELECT COUNT(*) as Total_Invoices
FROM   Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE  Vendors.VendorName = 'IBM'
GROUP BY VendorName
ORDER BY Total_Invoices DESC

select, on the other hand, is also called projection. you can safely remove it without taking any harm. but removing it on the GROUP BY clause is a very different thing already.

Upvotes: 4

Related Questions