SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    produce only 1 record which has the highest value

    I have 3 fields in myTable like the following.

    Code:
     data in myTable
    
    (ID) (name_class_blah_blah) (score)
    (1)  (Jane C3 ogdsbc)        (75) 
    (2)  (kate C2 ihc)           (65) 
    (3)  (Tom C1 kogv)           (85) 
    (4)  (Robert C3 kbgefxcg)    (90) 
    (5)  (Mary C1 bgfds)         (60)
    I have the following SQL and its result.
    Code:
    SQL
    select name_class_blah_blah  
    from myTable
    where name_class_blah_blah like '%C1%'
    
    result
    Tom C1 kogv
    Mary C1 bgfds
    The following is my target result.

    Code:
    target result
    
    Tom C1 kogv


    The following is the description of what I want.

    If there is only one record which has the word "C1", I like to produce the record.

    If there is two or more than two records which have the word "C1", I like to produce one record which has highest value in score field.


    Thanks in Advance

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    add the following to your code:

    Code:
     ORDER 
     BY score DESC
     LIMIT 1

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by daveman
    add the following to your code:

    Code:
     ORDER 
     BY score DESC
     LIMIT 1

    Thank you


Bookmarks

Posting Permissions

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