Select same rows in mysqli

How i can select five same num rows in mysqli,but i don’t want to use where=
I have same 5 num rows date in mysql,i want to select where is same date?

What are num rows?

Anyway there is no reason to avoid the WHERE condition in SQL. You need it in ANY case when you want to filter some records out of the whole table.

If this answer is not helping you any further you should consider to edit your question and tell us about your underlying problem and maybe show us some sample data

Select * from table where time is 123
If(num_rows ==3){
Echo “ok” }
But i want this if time is same,then echo “ok”
I think select time from table where time is same having count(3)

if you use the query

SELECT * FROM table WHERE time=123

then you will only get the rows that have the value 123 on the time field.

be warned that time is a reserved word in SQL so you better give your column another name than just time.

And yes you can use $result->num_rows to count the rows in the result.

If you don’t need the rows but only the the amount of rows than you could use

SELECT COUNT(*) AS hits FROM table WHERE time=123

But i have too many diferent same times?

  • what type is the column ‘time’ ?
  • show some code ( < 30 lines)
  • show some table records

Nick :Stiv
Time: 11
Nick :Stiv
Time : 11
Nick :Stiv
Time : 11
Nick :John
Time :22
Nick :John
Time :22
Nick :John
Time : 22
And …
I want where is 3 query same

If count time is 3 and is same
Then show nick
Nick :stiv
Nick : John

First question is, why?

SELECT name FROM table WHERE `time` = 11 LIMIT 3 ORDER BY name

Now it doesn’t matter if there are 50 with the same time, only 3 will be selected and the order by ensures the same ones, until someone else gets in the order.

A few questions to make sure we understand exactly what you are looking for.

Does your table have more than three ‘nick’ name for each person?

example…

Nick: Stiv, Time: 11
Nick: Stiv, Time: 11
Nick: Stiv, Time: 11
Nick: John, Time: 22
Nick: John, Time: 22
Nick: John, Time: 22
Nick: Stiv, Time: 2
Nick: Stiv, Time: 1
Nick: Stiv, Time: 5
Nick: John, Time: 9
Nick: John, Time: 7
Nick: John, Time: 3

or are there only ever three rows for each person and never more then three ?

Nick: Stiv, Time: 11
Nick: Stiv, Time: 22
Nick: Stiv, Time: 33
Nick: John, Time: 44
Nick: John, Time: 55
Nick: John, Time: 66

depending on your answer I may have more questions to ask to get more information on what you need.

Yes there is more names with same numbber,like kevin 66 kevin 66 kevin 66 and others

But exist like mateo who have number 99,number 77,number 46,but i want to select just names with 3 same numbers

ok I think I understand a bit more.

Is it possible to have more then three ‘nick’ with the same number.

Do you want to return rows with the highest number or lowest or just all that have three, or more than three of the same number for each ‘nick’

More than three of the same number for each ‘nick’ ,

More than three,but with same numbers like 666,like 777,like 888 for each nick

Sponsor our Newsletter | Privacy Policy | Terms of Service