Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 4 of 4

This is a discussion on Select fields starting with A, B, C etc in the Shared & Semi-Dedicated forum
The basic code I have to select the records I require is mysql_query('SELECT * FROM my_table WHERE field2 = "Associations" ORDER BY field1'); Can you ...

  1. #1
    JPC Member
    Join Date
    Sep 2001
    Posts
    12

    Select fields starting with A, B, C etc

    The basic code I have to select the records I require is

    mysql_query('SELECT * FROM my_table WHERE field2 = "Associations" ORDER BY field1');

    Can you please let me know how I modify this so that it only returns those records where field1 starts with the letter A, letter B, etc?

    I suppose I just need some help with the way wildcards are used.

    Thanks,

    James

  2. #2
    JPC Member
    Join Date
    May 2003
    Location
    Canada
    Posts
    46
    You ask for records where field1 starts with A, but your SQL example is using field2, with field1 used for sorting. Which do you really mean?

    In any case, wildcards only work with the LIKE operator. So to use your example, try this:

    Code:
    SELECT * FROM my_table WHERE field2 LIKE 'A%' ORDER BY field1
    Last edited by Darryl; 05-28-2003 at 12:43 AM.

  3. #3
    JPC Member
    Join Date
    Sep 2001
    Posts
    12
    Darryl, thanks for your help. Even with my stupidity in copying the wrong code you managed to work out what I needed.

    Is now working perfectly. Thanks.

    James

  4. #4
    JPC Member
    Join Date
    May 2003
    Location
    Canada
    Posts
    46
    Great. Glad I could help.

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
  •