I'm in a beginner SQL class using Microsoft SQL Studio. This is a very stupid question, I apologize but I can't figure it out. I'd like to know the proper syntax in order to do this, preferably in multiple ways because I know in SQL there isn't only one way to do things.
We haven't done any joins/subqueries so I'm not sure I should be using those, again this is a very basic intro class...
Where I need to do: Show INVENTORY table: Price, Part, Description (columns) Instructions: Display the Part, Description, and Price for the highest and lowest Priced parts in INVENTORY.
Here is what I have:
SELECT TOP(1) Price, Part, Description FROM INVENTORY
ORDER BY Price DESC;
This shows the highest price but how do I get the lowest price as well? Using AND doesn't work
I also did
SELECT MIN(price),
SELET MAX(price),
part,
description
from inventory
But it tells me that Description and Part aren't in aggregate functions.
I tried doing GROUP BY after WHERE as in GROUP BY part but then it says that description isnt in an aggregate function. So then I do GROUP BY part, description and then every result shows up when I only want the min and max.
So it looks like:
SELECT MIN(Price),
MAX(Price),
Part,
Description
FROM Inventory
GROUP BY Part, Description
But then it displays every result. I just want the highest and lowest results and using TOP with AND doesnt work.
Can someone help me with my syntax? What am I doing wrong? I'd appreciate two ways to show this, one using TOP and one using MIN/MAX if possible. I've been researching over an hour and even posted this to 4chan to ask for help.