1
I have a view where all its columns have been dubbed to make it more readable:
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| CNPJ | char(14) | NO | | NULL | |
| DATA CADASTRO | date | YES | | NULL | |
| RAZÃO SOCIAL | varchar(150) | YES | | NULL | |
| OPERADORA | varchar(100) | YES | | NULL | |
| LINHAS | int(11) | YES | | NULL | |
| CLASSIFICAÇÃO | varchar(2) | NO | | | |
| VIGENCIA | date | YES | | NULL | |
| MESES CONTRATO | int(21) | YES | | NULL | |
| FIDELIDADE | varchar(16) | NO | | | |
| VALOR GASTO | decimal(10,2) | YES | | NULL | |
| FIXO EMPRESA | varchar(17) | YES | | NULL | |
| GESTOR | varchar(150) | YES | | NULL | |
+----------------+---------------+------+-----+---------+-------+
Note that there are some fields where there is space between a word and another as for example RAZÃO SOCIAL
and if I try to execute such a query:
SELECT * FROM listarclientes WHERE "RAZÃO SOCIAL" like "EMPRESA FICTICIA LTDA ME";
It does not work for me that this company exists in my database. Now if I try to do the same but with the use of backticks:
SELECT * FROM listarclientes WHERE `RAZÃO SOCIAL` like "EMPRESA FICTICIA LTDA ME";
Now yes it brings me the desired result. Why do you consult with aliases which contains space in Mysql require the use of backticks?
NOTE: in the queries tested both with simple quotes '
as with double quotes "
and both result in blank.
NOTE²: the statement of aliases in view
in this example were made with double quotes "
but I also tested with simple quotes '
, and in the case without any kind of quotation marks (as is most common) it would not be possible in this case because it is composed of two words with space.
Todos os Fields da
view
sane aliases of the table’s original name. It’s silly but with backticks work, and I believe it only works for Mysql.– Patrick Perdigão
This is not alias. Do not use names like I said and you will not have this difficulty.
– Maniero
If I wear one
AS
to name a field it becomes an alias, right? Yes I will not use it, it sure is a bad practice just wanted to know how thebakcticks
in such a case.– Patrick Perdigão
That is, what you did is not, you just show that they are separate things. Their use is not for a type of case, it is orthogonal to all uses.
– Maniero
I feel like we’re talking about different things, I’m talking about when
view
that in case I did not put in question, and there I nicknamed all fields using theAS
, thus leaving theview
as presented in the question. but anyway this will not add to anything, what I asked you already managed to bring the answer.– Patrick Perdigão
You didn’t name anything, you created a view, you’re talking about something that doesn’t exist. If you used alias in the view and did not put in the question I can not do anything, I am talking about what you put in the question, even should have asked if it is relevant to the question, if it is not and should not have quoted it.
– Maniero