programing tip

표에서 1을 선택한다는 것은 무슨 의미입니까?

itbloger 2020. 7. 4. 11:15
반응형

표에서 1을 선택한다는 것은 무슨 의미입니까?


나는 다음과 같은 많은 질문을 보았습니다.

Select 1  
From table

이것은 무엇을 1의미하며 어떻게 실행될 것이며 무엇을 반환합니까?

또한 어떤 유형의 시나리오에서 사용할 수 있습니까?


SELECT 1 FROM TABLE_NAME"테이블에서 1 반환"을 의미합니다. 그것은 자체적으로 꽤 주목할 수 없으므로 일반적으로 함께 사용되며 WHERE종종 EXISTS(@gbn 메모와 같이 반드시 모범 사례는 아니지만 실제로 의미가없는 경우에도 주목할만큼 일반적입니다. 즉, 다른 사람들이 사용하기 때문에 즉시 사용할 수 있고 즉시 "더 분명해"집니다. 물론 그것은 점성 닭고기 대 계란 문제 일 수 있지만 일반적으로 머 무르지는 않습니다)).

 SELECT * FROM TABLE1 T1 WHERE EXISTS (
     SELECT 1 FROM TABLE2 T2 WHERE T1.ID= T2.ID
 );

기본적으로는 위의 표 2에서 해당 ID를 (이것은 분명 인위적인 예입니다,하지만 난 그게 아이디어를 전달 믿습니다. 개인적으로, 나는 아마 위의 할 것가 표 1에서 모든 것을 반환 SELECT * FROM TABLE1 T1 WHERE ID IN (SELECT ID FROM TABLE2);나는 같은 것을 볼로 우연히 설득력이없는 이유가없는 한 독자에게 더 분명하게 FAR ).

편집하다

실제로 지금까지 잊어 버린 한 가지 사례가 있습니다. 외부 언어를 사용하여 데이터베이스에 값이 있는지 확인하려는 경우 때때로 SELECT 1 FROM TABLE_NAME사용됩니다. 이것은 개별 열을 선택하는 것보다 큰 이점을 제공하지는 않지만 구현에 따라 SELECT *DB를 언어로 반환하는 열이 많을수록 데이터가 커지기 때문에 종종 을 수행하는 것보다 상당한 이점을 제공 할 수 있습니다 결과적으로 더 많은 시간이 소요됩니다.


select 1 from table테이블의 모든 행에 대해 상수 1을 반환합니다. 레코드가 where절 및 / 또는과 일치하는지 저렴하게 결정하려는 경우에 유용합니다 join.


당신이 같은 것을 의미한다면

SELECT * FROM AnotherTable
  WHERE EXISTS (SELECT 1 FROM table WHERE...) 

다음 보다 더 나은 신화 입니다1

SELECT * FROM AnotherTable
  WHERE EXISTS (SELECT * FROM table WHERE...) 

1또는 *(가) 무시됩니다 존재하고 당신이 당이 쓸 수있는 은 ANSI SQL 1992 표준 페이지 191 :

SELECT * FROM AnotherTable
  WHERE EXISTS (SELECT 1/0 FROM table WHERE...) 

그것이 말하는 것을 수행합니다-항상 정수 1을 반환합니다. where 절과 일치하는 레코드가 있는지 확인하는 데 사용됩니다.


select 1 from table 일부 데이터베이스에서는 연결을 테스트하기위한 쿼리로 사용되며 연결 풀에서 연결을 검색하거나 리턴 할 때 자주 사용됩니다.


결과는 1테이블의 모든 레코드에 대한 것입니다.__


널리 알려져 있지는 않지만 쿼리에는 HAVING절이없는 절이 있을 수 있습니다 GROUP BY.

In such circumstances, the HAVING clause is applied to the entire set. Clearly, the SELECT clause cannot refer to any column, otherwise you would (correct) get the error, "Column is invalid in select because it is not contained in the GROUP BY" etc.

Therefore, a literal value must be used (because SQL doesn't allow a resultset with zero columns -- why?!) and the literal value 1 (INTEGER) is commonly used: if the HAVING clause evaluates TRUE then the resultset will be one row with one column showing the value 1, otherwise you get the empty set.

Example: to find whether a column has more than one distinct value:

SELECT 1
  FROM tableA
HAVING MIN(colA) < MAX(colA);

To be slightly more specific, you would use this to do

SELECT 1 FROM MyUserTable WHERE user_id = 33487

instead of doing

SELECT * FROM MyUserTable WHERE user_id = 33487

because you don't care about looking at the results. Asking for the number 1 is very easy for the database (since it doesn't have to do any look-ups).


If you don't know there exist any data of you table or not, you can use following query:

SELECT cons_value FROM table_name;

For an Example:

SELECT 1 FROM employee;
  1. It will return a column which contains the total number of rows & all rows have the same constant value 1 (for this time it returns 1 for all rows);
  2. If there is no row in your table it will return nothing.

So, we use this SQL query to know if there is any data in the table & the number of rows indicate how many rows are exist in this table.


This means that You want a value "1" as output or Most of the time used as Inner Queries because for some reason you want to calculate the outer queries based on the result of inner queries.. not all the time you use 1 but you have some specific values...

This will statically gives you output as value 1.


If you just want to check a true or false based on the WHERE clause, select 1 from table where condition is the cheapest way.


I see it is always used in SQL injection,such as:

www.urlxxxxx.com/xxxx.asp?id=99 union select 1,2,3,4,5,6,7,8,9 from database;

These numbers can be used to guess where the database exists and guess the column name of the database you specified.And the values of the tables.


it simple means that you are retrieving the number first column from table ,,,,means select Emply_num,Empl_no From Employees ; here you are using select 1 from Employees; that means you are retrieving the Emply_num column. Thanks


The reason is another one, at least for MySQL. This is from the MySQL manual

InnoDB computes index cardinality values for a table the first time that table is accessed after startup, instead of storing such values in the table. This step can take significant time on systems that partition the data into many tables. Since this overhead only applies to the initial table open operation, to “warm up” a table for later use, access it immediately after startup by issuing a statement such as SELECT 1 FROM tbl_name LIMIT 1


This is just used for convenience with IF EXISTS(). Otherwise you can go with

select * from [table_name]

이미지 'IF EXISTS'의 경우 지정된 조건을 가진 행이 존재하는지 또는 행의 내용이 중요하지 않다는 것을 알아야합니다.

select 1 from Users

위의 예제 코드는 no를 반환합니다. 행 수는 no와 같습니다. 단일 열에 1 인 사용자

참고 URL : https://stackoverflow.com/questions/7171041/what-does-it-mean-by-select-1-from-table

반응형