+ Reply to Thread
Results 1 to 2 of 2

Thread: match one string to two columns

  1. #1

    match one string to two columns

    I have a "users" table which contains users first and last names:
    id | first_name | last_name | 
     1 | daniel     | johnston  |
     2 | jane       | austin    |
    I'd like to use a select a set of users based on a single string (matching to the beginning of both first_name and last_name. So if I search for "a", both records will be returned. If I search for "ab", only the the first record will be returned.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    You can use the OR :
    SELECT id, first_name, last_name 
    FROM users 
    WHERE (first_name LIKE 'ab%' OR last_name like 'ab%')

+ Reply to Thread

Tags for this Thread


Posting Permissions

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