2

Am trying to fetch the number of records in the table using Count(*) along with my query condition
Sample Table is
Table: STUD_NAME

 Id Name 1 Steven 2 smith 2 Ben 1 Willy 

My query is

 select std.name from STUD_Name where id='2' 

for this it will display the output as "Smith" and "Ben", along with i need the total number of records in the STUD_NAME table.

By right it should display the total records as "4", please help me out to solve this issue and how to form the query in this case

3 Answers 3

3
SELECT name, cnt as total_count FROM ( SELECT id name, count(*) over () as cnt FROM stud_name ) t WHERE id = 2 

Assuming that id is a numeric column the single quotes around the value 2 are not needed (and are actually harmful due to the implicit data type conversion that happens in the background)

Sign up to request clarification or add additional context in comments.

1 Comment

Hi again some problem in my query, I need to display the count according to my where condition, "select STUD_NAME.name, from STUD_NAME where id='2', I need to display name which matched to id "2" + no of rows which fetched for id'2', its bid priority pls help me out
1

What about:

select std.name ,(select count(1) from STUD_Name) nrofstds from STUD_Name std where std.id='2' 

Comments

0
select STUD_NAME.name, CNT.count from STUD_NAME , (select count(*) COUNT from STUD_NAME) CNT where id='2' 

1 Comment

Hi again some problem in my query, I need to display the count according to my where condition, "select STUD_NAME.name, from STUD_NAME where id='2', I need to display name which matched to id "2" + no of rows which fetched for id'2', its bid priority pls help me out

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.