Jump to content

Recommended Posts

I was wondering how you would search an alias column. For example, I want to search a name with two CONCAT fields as name. Here's what I'm trying, but it doesn't show up with anything even though I know the name is there:

 

SELECT
CONCAT(patron.firstname, " ", patron.lastname) AS name
FROM
patron
WHERE
'name' = "*******"

Link to comment
https://forums.phpfreaks.com/topic/149547-solved-alias-searching/
Share on other sites

SELECT CONCAT(patron.firstname, ' ', patron.lastname) AS name
  FROM patron
  WHERE name = '*******';

 

name is an identifier. Those do not have single nor double quotes around them in SQL. Otherwise they are string literals.

 

If you do e.g. 'name' = 'foo' then you are selecting all rows from patron where it is true that the string name is the same as the string foo. This is never true and as such you will never get any results.

 

If you do name = 'foo' then you are selecting all rows from patron where it is true that the column[/tt] (or alias) called name equals the string foo. This may or may not be true for some rows, but for those rows where that statement is true will be returned, the others won't.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.