If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to match maximum character

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-17-11, 12:35
karthik_192me karthik_192me is offline
Registered User
 
Join Date: May 2011
Posts: 3
How to match maximum character

hi
I m new to this group,new bee to sql,i need help.my DB is MDL like

digit,name
937,RAM
9379,GURU
93,HARI

sql query i tried is
SELECT name,digit from MDL where LEFT('93799321205',length(digit))=digit;
i need to match maximum character, i shd get output as "9379,GURU"..pl help
Reply With Quote
  #2 (permalink)  
Old 05-17-11, 14:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
SELECT name,digit from MDL where LEFT('93799321205',length(digit))=digit
ORDER BY length(digit) DESC LIMIT 1

note: does not include ties
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-19-11, 11:03
karthik_192me karthik_192me is offline
Registered User
 
Join Date: May 2011
Posts: 3
Post Thank you!!

Thank u very much..it working perfectly...
one more issue....my DB is

country| id |Plan
DE | XX1 | P
US | XX2 | W
US | XX3 | P
DE | XX4 | P

my output shd like

Plan_|_DE_|_US
W | 0 | 2
P | 2 | 1

i m using DECODE option, not getting exact output...Pl help me

SELECT plan,count(DECODE(country,'DE',id)),count(DECODE(c ountry,'US',id))
ORDER BY Plan;
Reply With Quote
  #4 (permalink)  
Old 05-19-11, 11:55
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
new question new thread please
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 05-19-11, 12:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by karthik_192me View Post
i m using DECODE option, not getting exact output...Pl help me
DECODE is oracle, not mysql -- ask in the oracle forum
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On