Select from another select without temporary table?

Mateusz

There is table of numbers containing values [1,1,2,3,7,3,4,2,7] I want to select only duplicates so output set would contain [1,2,3,7] so 4 is filtered out.

I have code that I did like this:

DROP TABLE #tempTable;
SELECT  [numbers] as nums, COUNT(*) as cny
INTO #tempTable
  FROM [testBase].[dbo].[numbers] group by numbers;

SELECT nums from #tempTable where nums > 1;

Now I would like to know if I can get it without first selecting to #tempTable? Something more like select from select or is it only way I can do it?

hgulyan

The same in one query.

Conditions that are made after GROUP BY should be added to HAVING clause.

SELECT  [numbers] as nums, COUNT(*) as cny
FROM [testBase].[dbo].[numbers] 
GROUP BY numbers
HAVING COUNT(*) > 1

More on this

HAVING (Transact-SQL)

Having clause tutorial

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

select * from (select * from table)

분류에서Dev

Select from one table and order by column of another table

분류에서Dev

best way to select data from one table or another

분류에서Dev

MySql select by excluding all id from another table

분류에서Dev

SELECT FROM table, ORDER BY IF (...)

분류에서Dev

PostgreSQL return select results AND add them to temporary table?

분류에서Dev

Should I use a nested select or create a temporary table for this situation in SQL?

분류에서Dev

Select all fields from a table where a field in another table with an ID is equal to a string

분류에서Dev

SELECT array of cols FROM table

분류에서Dev

RegEx in select from table in db

분류에서Dev

SELECT * FROM table Where CURDATE ()

분류에서Dev

select a field values that are not found in another table

분류에서Dev

MySQL select data from table and inner join the union all selection from another two identical tables

분류에서Dev

CREATE TABLE AS select * from partitioned table

분류에서Dev

SELECT * INTO [newdatabase]. [table] FROM [otherdatabase]. [table]

분류에서Dev

Select results from one query to another

분류에서Dev

How to select column in table by creating row in another table in MySQL

분류에서Dev

select * from table where id = select max id in codeigniter

분류에서Dev

how select from table where datetime=date

분류에서Dev

Select fields from table with DISTINCT field

분류에서Dev

LINQ select data from many table

분류에서Dev

MySQL Best select query from two table

분류에서Dev

Select from table where the date is later then today

분류에서Dev

Select drop down from table array

분류에서Dev

How to select the following things from psql table?

분류에서Dev

SELECT * FROM MULTIPLE + DYNAMIC table_name

분류에서Dev

mysql select * from table group by id with rollup

분류에서Dev

Select rows by criteria in another data.frame without for loop in R

분류에서Dev

Select from Select

Related 관련 기사

  1. 1

    select * from (select * from table)

  2. 2

    Select from one table and order by column of another table

  3. 3

    best way to select data from one table or another

  4. 4

    MySql select by excluding all id from another table

  5. 5

    SELECT FROM table, ORDER BY IF (...)

  6. 6

    PostgreSQL return select results AND add them to temporary table?

  7. 7

    Should I use a nested select or create a temporary table for this situation in SQL?

  8. 8

    Select all fields from a table where a field in another table with an ID is equal to a string

  9. 9

    SELECT array of cols FROM table

  10. 10

    RegEx in select from table in db

  11. 11

    SELECT * FROM table Where CURDATE ()

  12. 12

    select a field values that are not found in another table

  13. 13

    MySQL select data from table and inner join the union all selection from another two identical tables

  14. 14

    CREATE TABLE AS select * from partitioned table

  15. 15

    SELECT * INTO [newdatabase]. [table] FROM [otherdatabase]. [table]

  16. 16

    Select results from one query to another

  17. 17

    How to select column in table by creating row in another table in MySQL

  18. 18

    select * from table where id = select max id in codeigniter

  19. 19

    how select from table where datetime=date

  20. 20

    Select fields from table with DISTINCT field

  21. 21

    LINQ select data from many table

  22. 22

    MySQL Best select query from two table

  23. 23

    Select from table where the date is later then today

  24. 24

    Select drop down from table array

  25. 25

    How to select the following things from psql table?

  26. 26

    SELECT * FROM MULTIPLE + DYNAMIC table_name

  27. 27

    mysql select * from table group by id with rollup

  28. 28

    Select rows by criteria in another data.frame without for loop in R

  29. 29

    Select from Select

뜨겁다태그

보관