SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to select distinct variable using like...

    Hi,
    I m trying to use select statement in order to select a distinct word like 'c', but in the database i only want to select c when it occurs on its own not when it appears in another word. eg i need to select the alphabet 'c' in 'the cat category is c' but not the 'c' in 'cat' or 'category'.
    I have used the code below but this seem to count all 'c'


    select set rsTypes2 = con.execute("SELECT COUNT(two) AS total FROM march where two like '%c%'")

    any idea how to implement this

    cheers

  2. #2
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ummm I don't understand what your asking? You only want to match words that start with c or what?

    or do you only want to find a value of c and nothing else?

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about the confusion.
    Yes I only want a value of c and nothing else. for instance, in the follwing sentence: 'the cat sat on the c', i only want to count the 'c' but not the 'c' in the 'cat'


    thanks

  4. #4
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    Kingston
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perhaps ...
    Code:
    where two like '% c' or two like 'c %' or two like '% c %'
    Bear in mind this could get slow as your database grows.

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    ole dawg on right track

    other combos to look for:
    '% c.%'
    '% c,%'
    '% c?%'
    '% c!%'

    and hey, let's not forget "c? i tole ya!" which requires 'c?%'

    c'mon, i'm sure y'all can "c" where this is going...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thanks guys


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
  •