By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

finding the max

100+
P: 110
I have a table as follows

code
PB0001AA
PB0001AB
PB0001AC
PX0001AA
PX0001AB
PX0001AC
PX0001AD
PC0001AA
PC0001AB


I want to get data of only max
eg in the above case
PB0001AC
PX0001AD
PC0001AB







Thanks in advance
Apr 19 '13 #1
Share this Question
Share on Google+
4 Replies


100+
P: 110
Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(code) FROM exmaster WHERE code IN (SELECT code FROM exmaster) GROUP BY SUBSTRING(code,1,6)
is this ok ?
Apr 20 '13 #2

100+
P: 110
Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(code) FROM exmaster WHERE GROUP BY SUBSTRING(code,1,6)
Apr 20 '13 #3

100+
P: 158
Hey SSG001, you can use like this,

Expand|Select|Wrap|Line Numbers
  1. select MAX(Name) from Table_1 where Name like 'PB0001A%' union select MAX(Name) from Table_1 where Name like 'PX0001A%' union select MAX(Name) from Table_1 where Name like 'PC0001A%'
Apr 20 '13 #4

Rabbit
Expert Mod 10K+
P: 12,365
Please use code tags when posting code.

You can do this:
Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(code)
  2. FROM exmaster
  3. GROUP BY SUBSTRING(code,1,6)
Apr 20 '13 #5

Post your reply

Sign in to post your reply or Sign up for a free account.