Results 1 to 5 of 5
  1. #1
    Join Date
    May 2011
    Posts
    3

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    SELECT name,digit from MDL where LEFT('93799321205',length(digit))=digit
    ORDER BY length(digit) DESC LIMIT 1

    note: does not include ties
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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;

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    new question new thread please
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •