5
In relational model condition, I have to specify the prefix of the table, I’m sure?
Example: SELECT c.nome, c.idade, a.nome, a.idade FROM
...
What I wanted to know is if you can’t do something like this:
SELECT c(nome, idade), a(nome, idade) FROM
...
Can you give this "streamlined" code, or the only way is to prefix everything?
Unlike this, I think only the
SELECT c.*, a.* FROM...
– Ismael
That’s the answer, @Islam
– Giuliana Bezerra
It is not possible to do this. The bank will try to find a c function and a function in this example:
SELECT c(nome, idade), a(nome, idade) FROM
– Reginaldo Rigo
@Reginaldorigo But that was exactly the problem. I wasn’t asking literally, but something similar, you know? But I don’t think there really is =(
– Seu Madruga
@I was trying to get away from this option because I think it consumes more resources, no?
– Seu Madruga
As Ismael said
c( nome, idade )
must bec.*
– Reginaldo Rigo
Using * indiscriminately will actually consume more processing and network bandwidth, as ALL table fields (of your query) will be required. In addition, it will directly influence the index chosen by SGDB to perform the query. It can have bad consequences when working with Views as well. Particularly, I always declare all fields.
– Ismael
Also because table changes can 'break' those codes with
*
– Reginaldo Rigo
Thanks to all for the clarifications. I will declare everything with prefix even. Thanks! =)
– Seu Madruga
There is no way to do this. Each field of the table returned in
SELECT
is unique, so you have to prefix with the alias or table name if there is more than one field with the same name in the tables used inFROM
. Using * is not a good option, as @Smael mentioned earlier. But this "streamlined" you mentioned may not be such an effort, since you mount the query once and do not change all the time, it is worth making a very readable query, easy to understand and will not generate problems later.– Ricardo Pontual
@inovapixel Hello, consider accepting my answer if it has been useful to you. If you think she’s incomplete or doesn’t respond to you, make the appropriate comments so I can improve her.
– Ismael