Jump to content

[SOLVED] Alias searching


lordzardeck

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.