Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Posts
    23

    Unanswered: Select from where first charcter starts with J

    Hi all,

    What would the query be where I select from a table where the first letter of the data in a field starts with a certain letter? For instance J.
    Or would I just have to select all and then filter through in php?

    Thanks,
    Jason
    SnapSlides.Com - Create slideshows online to share with friends and family.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select foo from bar where left(qux,1) = 'j'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2004
    Posts
    480
    never a need to filter with php. the only time you would probably need to use php would be for displaying your data in other ways than you can pull it out of the database.


    Code:
    Select foo from yourtable
    where left(foo,1)='j'

  4. #4
    Join Date
    Mar 2004
    Posts
    480
    You won by a minute here, happy? <lol>

  5. #5
    Join Date
    Jul 2004
    Posts
    23
    Thanks for the replys

    So in your examples, in the (), the first word (foo and qux), what do those reference? The field?
    Also, is this case-sensitive?

    Thanks,
    Jason
    SnapSlides.Com - Create slideshows online to share with friends and family.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    foo is the canonical example of a metasyntactic variable

    no, the sql is not case-sensitive
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Feb 2005
    Posts
    5
    Isn't it easier just to say... SELECT foo FROM bar WHERE variable = 'J%'? Or am I missing something obvious here?
    Last edited by canman; 02-20-05 at 08:44.

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well, canman, you could, except that you would want to change it from

    ... WHERE variable = 'J%'

    to

    ... WHERE variable LIKE 'J%'

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Jul 2004
    Posts
    23
    WHERE variable LIKE 'J%'
    Aye, I shall use that one, I never thought of that.

    Thanks all
    Jason
    SnapSlides.Com - Create slideshows online to share with friends and family.

Posting Permissions

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