-1

I have a database with firstname and lastname columns. Is there a way to query these togheter, for example:

SELECT * FROM TABLE_NAME WHERE firstname + ' ' + lastname = :fullName

Currently this query gives me multiple results even when the firstname and lastname do not match at all with the fullName variable.

jarlh
  • 42,561
  • 8
  • 45
  • 63
lopaxxxkzz
  • 51
  • 4
  • 1
    You can use `CONCAT()` to .. concatenate values – brombeer Nov 24 '22 at 15:48
  • Also, just to be certain of the operator precedence, you can put parens around the `firstname + ' ' + lastname`. – Chris Maurer Nov 24 '22 at 16:26
  • Which dbms are you using? AFAIK, `+` for concatenation is SQL Server only. ANSI SQL has `||` concatenation operand. – jarlh Nov 24 '22 at 18:48
  • 1
    Does this answer your question? [String concatenation in MySQL](https://stackoverflow.com/questions/5975958/string-concatenation-in-mysql) – Nico Haase Nov 25 '22 at 11:13

1 Answers1

2

SELECT * FROM TABLE_NAME WHERE CONCAT(firstname, ' ', lastname) = :fullName

Walter KT
  • 52
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 28 '22 at 11:15