SQL 选择和项目操作有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5432573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:51:54  来源:igfitidea点击:

What is the difference between Select and Project Operations

sqlselectrelational-algebra

提问by gizgok

I'm referring to the basic relational algebra operators here.
As I see it, everything that can be done with project can be done with select.

我在这里指的是基本的关系代数运算符。
在我看来,可以通过项目完成的所有事情都可以通过选择完成。

I don't know if there is a difference or a certain nuance that I've missed.

我不知道是否存在差异或我遗漏的某些细微差别。

回答by sgokhales

Select Operation :This operation is used to select rows from a table (relation) that specifies a given logic, which is called as a predicate. The predicate is a user defined condition to select rows of user's choice.

选择操作:此操作用于从指定给定逻辑的表(关系)中选择行,称为predicate. 谓词是用户定义的条件,用于选择用户选择的行。

Project Operation :If the user is interested in selecting the values of a few attributes, rather than selection all attributes of the Table (Relation), then one should go for PROJECTOperation.

项目操作:如果用户有兴趣选择几个属性的值,而不是选择表(关系)的所有属性,那么应该选择PROJECT操作。

See more : Relational Algebra and its operations

查看更多:关系代数及其运算

回答by Krishna Pal

PROJECTeliminates columns while SELECTeliminates rows.

PROJECT消除列,而SELECT消除行。

回答by EmergeStronger

In Relational algebra 'Selection' and 'Projection' are different operations, but the SQL SELECT combines these operations in a single statement.

在关系代数中,“选择”和“投影”是不同的操作,但 SQL SELECT 将这些操作组合在一个语句中。

Select retrieves the tuples (rows) in a relation (table) for which the condition in 'predicate' section (WHERE clause) stands true.

Select 检索关系(表)中“谓词”部分(WHERE 子句)中的条件为真的元组(行)。

Project retrieves the attributes (columns) specified.

Project 检索指定的属性(列)。

The following SQL SELECT query:

以下 SQL SELECT 查询:

select field1,field2 from table1 where field1 = 'Value';

is a combination of both Projection and Selection operations of relational algebra.

是关系代数的投影和选择操作的组合。

回答by user4980372

Project is not a statement. It is the capability of the select statement. Select statement has three capabilities. They are selection,projection,join. Selection-it retrieves the rows that are satisfied by the given query. Projection-it chooses the columns that are satisfied by the given query. Join-it joins the two or more tables

项目不是声明。这是 select 语句的能力。Select 语句具有三个功能。它们是选择、投影、连接。选择 - 它检索给定查询满足的行。投影 - 它选择给定查询满足的列。join-it 连接两个或多个表

回答by Mohammad Heydari

Projectwill effects Columns in the table while Selecteffects the Rows. on other hand Projectis use to select the columns with specefic properties rather than Select the all of columns data

Project将影响表中的列,同时Select影响行。另一方面Project用于选择具有特定属性的列而不是选择所有列数据

回答by akanksha malik

selection opertion is used to select a subset of tuple from the relation that satisfied selection condition It filter out those tuple that satisfied the condition .Selection opertion can be visualized as horizontal partition into two set of tuple - those tuple satisfied the condition are selected and those tuple do not select the condition are discarded sigma (R) projection opertion is used to select a attribute from the relation that satisfied selection condition . It filter out only those tuple that satisfied the condition . The projection opertion can be visualized as a vertically partition into two part -are those satisfied the condition are selected other discarded Π(R) attribute list is a num of attribute

选择操作用于从满足选择条件的关系中选择元组的子集过滤掉那些满足条件的元组。元组不选择条件被丢弃 sigma(R) 投影操作用于从满足选择条件的关系中选择一个属性。它只过滤掉那些满足条件的元组。投影操作可以可视化为垂直划分为两部分 - 满足条件的那些被选中,其他丢弃的 Π(R) 属性列表是属性的数量

回答by rashedcs

Select extract rows from the relation with some condition and Project extract particular number of attribute/column from the relation with or without some condition.

选择从具有某些条件的关系中提取行,并从具有或不具有某些条件的关系中选择项目提取特定数量的属性/列。

回答by Shaykh Aawmir

The difference between the project operator (π) in relational algebra and the SELECT keyword in SQL is that if the resulting table/set has more than one occurrences of the same tuple, then π will return only one of them, while SQL SELECT will return all.

关系代数中的项目运算符 (π) 与 SQL 中的 SELECT 关键字的区别在于,如果结果表/集有多个相同元组出现,则 π 将仅返回其中一个,而 SQL SELECT 将返回全部。

回答by Binod Regmi

select just changes cardinality of the result table but project does change both degree of relation and cardinality.

select 只是改变结果表的基数,但项目确实改变了关系度和基数。

回答by Malala Victor

The difference come in relational algebra where project affects columns and select affect rows. However in query syntax, select is the word. There is no such query as project. Assuming there is a table named users with hundreds of thousands of records (rows) and the table has 6 fields (userID, Fname,Lname,age,pword,salary). Lets say we want to restrict access to sensitive data (userID,pword and salary) and also restrict amount of data to be accessed. In mysql maria DB we create a view as follows ( Create view user1 as select Fname,Lname, age from users limit 100;) from our view we issue (select Fname from users1;) . This query is both a select and a project

不同之处在于关系代数,其中项目影响列而选择影响行。但是在查询语法中,select 就是这个词。没有像 project 这样的查询。假设有一个名为 users 的表,有数十万条记录(行),该表有 6 个字段(userID、Fname、Lname、age、pword、salary)。假设我们要限制对敏感数据(用户 ID、密码和工资)的访问,并限制要访问的数据量。在 mysql maria DB 中,我们创建一个视图如下( Create view user1 as select Fname,Lname, age from users limit 100;)从我们发出的视图(select Fname from users1;)。此查询既是选择又是项目