Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Order By Column From SELECT Without Using Temp Table

Well, I know we can hide order by column from select statement by using temp tables. Just wondering how to do the same without using temp tables?

As the db I'm working is so huge, adding temp tables impact query performance a lot.

My Query is something like following:

SELECT DISTINCT
  Col1,
  MAX(Col2),
  MAX(Col3),
  Col4
FROM 
  Table1
Group By
  Col4,
  Col1
Order By
  Col4

Now all i want is to get rid of Col4 from Output without using temp tables. Can't even do that using inner query. Thanks.

like image 406
ViKiNG Avatar asked Jan 17 '26 14:01

ViKiNG


1 Answers

If your Col4 is computed/derived and it has to be in original select, you may simple make an outer query:

SELECT G.Col1, G.C2, G.C3 from
(SELECT DISTINCT
  Col1,
  MAX(Col2) AS C2,
  MAX(Col3) AS C3,
  Col4
FROM 
  Table1
Group By
  Col4,
  Col1
Order By
  Col4) AS G
like image 194
Tibor002 Avatar answered Jan 20 '26 06:01

Tibor002



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!