Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4057840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:00:15+00:00 2026-05-20T15:00:15+00:00

In my table I have a field firstname and a field lastname. I would

  • 0

In my table I have a field “firstname” and a field “lastname”. I would like to select all records where firstname + space + lastname is a certain value.

I’ve tried this:

$sql = "SELECT * FROM sam_users WHERE (user_firstname + ' ' + user_lastname LIKE ?)";

But this isn’t working. With Google I’ve found something about using ||, but I don’t really understand how I should use that operator. Note that I don’t want to use an or-operator (what || is in many languages), but something to concatenate 2 fields (with a space between them) and using a LIKE on that.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:00:15+00:00Added an answer on May 20, 2026 at 3:00 pm

    With MySQL, you can use CONCAT:

    SELECT * FROM sam_users 
      WHERE CONCAT(user_firstname, ' ', user_lastname) LIKE ?
    

    or CONCAT_WS (which ignores NULL values):

    SELECT * FROM sam_users 
      WHERE CONCAT_WS(' ', user_firstname, user_lastname) LIKE ?
    

    However, MySQL won’t be able to use any indices when performing this query. If the value of the pattern argument to LIKE begins with a wildcard, MySQL won’t be able to use indices, so comparing to a generated value (instead of a column) won’t make a difference.

    You can also set the MySQL server SQL mode to “ANSI” or “PIPES_AS_CONCAT” to use the || operator for string concatenation.

    SET @@sql_mode=CONCAT_WS(',', @@sql_mode, 'PIPES_AS_CONCAT');
    SELECT * FROM sam_users 
      WHERE (user_firstname || ' ' || user_lastname) LIKE ?
    

    This sets the SQL mode for the current session only. You’ll need to set @@sql_mode each time you connect. If you wish to unset ‘PIPES_AS_CONCAT’ mode in a session:

    SET @@sql_mode=REPLACE(@@sql_mode, 'PIPES_AS_CONCAT', '');
    

    MySQL appears to remove any extra commas in @@sql_mode, so you don’t need to worry about them.

    Don’t use SELECT *; select only the columns you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such Linq, I would like to get all records from Orders table
I have a set of data that looks like this: Before FirstName LastName Field1
I have a table with three fields, FirstName, LastName and Email. Here's some dummy
All rows in a table have a type field which is either 0 or
trasaction table description field have some value it is worked fine. description feild default
I have records that have FirstName and LastName for individuals, and CompanyName for companies.
Hi all i have the following table called student in SQLite database. this is
I have table in my database names User with fields: Id FirstName LastName LoginName
I have a user table 'users' that has fields like: id first_name last_name ...
In my db table I have a field float where I store cost of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.