How to retrieve top 3 highest and 3 lowest values in SQL? I created a table as shown below,
CREATE TABLE SALES
(
       SALE_ID          INTEGER,
       PRODUCT_ID       INTEGER,
       YEAR             INTEGER,
       QUANTITY         INTEGER,
       PRICE                INTEGER
);

Now i want query which retrieves three highest and three lowest price products in the sales table. I am new in SQL please help. I tried a lot of queries but nothing happen. below is my query.
SELECT TOP 3 PRICE FROM SALES
Union 
SELECT PRICE FROM SALES order by PRICE;
You can also use something like this (see the fiddle here) - it's perhaps more flexible than the other answer - in any case, you should look at learning window functions in SQL - they can be very powerful.
First, table and data:
CREATE TABLE sale
(
  SALE_ID          VARCHAR (10),
  PRODUCT_ID       INTEGER,
  YEAR             INTEGER,
  QUANTITY         INTEGER,
  PRICE                INTEGER
);


INSERT INTO sale (sale_id, price) VALUES 
('Item_1', 1), ('Item_2', 2), ('Item_3', 3), ('Item_4', 4), ('Item_5', 5), ('Item_6', 6), 
('Item_7', 7), ('Item_8', 8), ('Item_9', 9), ('Item_10', 10), ('Item_11', 11), 
('Item_12', 12), ('Item_13', 13), ('Item_14', 14);

Run this SQL:
SELECT 
  t.sale_id, 
  t.price, 
  CASE 
    WHEN t.rn_up &lt;= 3 THEN 'Low priced' 
    WHEN t.rn_down &lt;= 3 THEN 'High priced'
  END as price_range
FROM 
(
  SELECT
    s.sale_id,
    s.price,
    ROW_NUMBER() OVER (ORDER BY s.price ASC) AS rn_up,
    ROW_NUMBER() OVER (ORDER BY s.price DESC) AS rn_down
  FROM sale s
) AS t
WHERE t.rn_up &lt;= 3 OR t.rn_down &lt;= 3
ORDER BY t.price ASC;

Result:
sale_id price     price_range
Item_1      1      Low priced
Item_2      2      Low priced
Item_3      3      Low priced
Item_12    12     High priced
Item_13    13     High priced
Item_14    14     High priced
6 rows

If you want to deal with ties - I've added a record:
INSERT INTO sale (sale_id, price) VALUES  ('Item_43', 13);

And now, the results are (more or less) arbitrary - I run the same query and I get the same results - I reckon it may be the INSERTion order of records that have a price of 13 (see the fiddle).
What you can do then is use DENSE_RANK() as follows:
SELECT 
  t.sale_id, 
  t.price, 
  CASE 
    WHEN t.rn_up &lt;= 3 THEN 'Low priced' 
    WHEN t.rn_down &lt;= 3 THEN 'High priced'
  END as price_range
FROM 
(
  SELECT
    s.sale_id,
    s.price,
    DENSE_RANK() OVER (ORDER BY s.price ASC) AS rn_up,
    DENSE_RANK() OVER (ORDER BY s.price DESC) AS rn_down
  FROM sale s
) AS t
WHERE t.rn_up &lt;= 3 OR t.rn_down &lt;= 3
ORDER BY t.price ASC, sale_id;

Result:
sale_id price   price_range
 Item_1     1   Low priced
 Item_2     2   Low priced
 Item_3     3   Low priced
Item_12    12   High priced
Item_13    13   High priced    --  &lt;&lt;=== Note: now we have 2 items with price 13!
Item_43    13   High priced
Item_14    14   High priced

As mentioned in comments, what exact SQL statement you'll use will depend on your  requirements  - I would just urge you to spend some time studying window functions - they'll repay that time ten times over!