0

please tell me how i make a sql query for
selecting data's from a table where that data repeated 4 times in that column

5
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rohinireddy
0

to select a column in a table we use the select command the command will be select * from table name....

0

I would think that would be something like (using a table called Table1 with one column called "Name"):

SELECT * FROM (Select Table1.Name, Count(Table1.Name) as NumNames from Table1 group by Table1.Name)  WHERE NumNames=4

Edited by pahag: Clarification.

0

Hi,
Aggregate functions cannot be used in WHERE clause directly. Instead you can apply HAVING clause to GROUP BY clause. Try this:

SELECT Table1.Name, Count(Table1.Name) AS NumNames 
  FROM Table1 GROUP BY Table1.Name HAVING NumNames=4;

This will select all occurrences of Table1.Name that appear four times in table1

btw, if you want to use aggregate functions in WHERE clause for some reason, you need to wrap them in UDFs. UDFs can freely be used in WHERE clause (at the cost of performance).

-- tesu

Edited by tesuji: n/a

0

please tell me how i make a sql query for
selecting data's from a table where that data repeated 4 times in that column

select [column name] from table name where (condition)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.