选择中是否存在星号会排除其他列? [英] does the existence of an asterisk in a select exclude other columns?
问题描述
这个问题全都与懒惰有关...我想做这样的事情:
This question is all about laziness... I'd like to do something like this:
select some_func(some_col), * from my_table
这样我就不必这样做:
select some_func(some_col), col_1, col_2... col_ad_infinitum from my_table
有什么办法可以使第一个查询正常工作?这是我在运行它时遇到的错误:
Is there any way to make the first query work? This is the error I get when I run it:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* from my_table' at line 1
推荐答案
您的意思是在MySQL中您的第一个查询:
Do you mean that in MySQL your first query:
SELECT some_func(some_col), *
FROM my_table
会产生此错误吗?:
错误代码:1064.您的SQL语法有错误;请参见.检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的"*"附近使用
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*' at line 1
您可以将代码更改为(这不会导致错误!):
You can change your code into (this results in no errors!):
SELECT *, some_func(some_col)
FROM my_table
或添加到此,如果您想首先拥有计算列:
or into this, if you want to have the calculated columns first:
SELECT some_func(some_col), t.*
FROM my_table AS t
这篇关于选择中是否存在星号会排除其他列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!