什么是“select 1 from"?做? [英] What does "select 1 from" do?

查看:33
本文介绍了什么是“select 1 from"?做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一些文章,但真的不明白 select 1 from 是做什么的?有人说你应该使用 select 1 而不是 select *".这是一个示例表:

I read some articles but really didn't understand what does select 1 from do? Someone says "you should use select 1 instead of select *". Here is an example table:

cust_id     cust_name       cust_address

1000000001  Village Toys    Mapl
1000000002  Kids Place      South
1000000003  Fun4All         Sunny
1000000004  Fun4All         Riverside
1000000005  The Toy Store   53rd

当我写select 1 from customer_table这个语句有什么作用时,结果是什么?

What will the result be when I write select 1 from customer_table what does this statement do?

推荐答案

select 1 from table

将为表中的每一行返回一列 1.您可以将它与 where 语句一起使用来检查您是否有给定键的条目,如:

will return a column of 1's for every row in the table. You could use it with a where statement to check whether you have an entry for a given key, as in:

if exists(select 1 from table where some_column = 'some_value')

您的朋友可能说的是,与其使用 select * from table 进行批量选择,您应该准确指定您需要的列,原因有两个:

What your friend was probably saying is instead of making bulk selects with select * from table, you should specify the columns that you need precisely, for two reasons:

1) 性能 &您可能会检索到比实际需要更多的数据.

1) performance & you might retrieve more data than you actually need.

2) 查询的用户可能依赖于列的顺序.如果您的表更新,客户端将收到与预期不同的列.

2) the query's user may rely on the order of columns. If your table gets updated, the client will receive columns in a different order than expected.

这篇关于什么是“select 1 from"?做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆