How to display 3 different records from the database, only 3 and different, that is: in the database there are 4 records:

Запись 1 Запись 2 Запись 3 Запись 4 

It is necessary to make so that only 3 records and different would be displayed. Requests etc on mysqli

  • SELECT * FROM mytable LIMIT 3; - have you tried? - Opalosolo
  • I tried, so I have the same 3 entries are displayed. - Dimcheg
  • one
    @ Dmitry Astafyev do you need duplicate records to be ignored? - intro94

2 answers 2

You have already been answered ... If you think a little, then you will come to

 Select * from table where status = 'top' LIMIT 3 
     SELECT * FROM table ORDER BY RAND() LIMIT 3 
    • why do i need a random if I need to display certain records Select * from table where status = 'top' is needed so that they would be output 3 no more, if 2 records with the value top will display 2 ... - Dimcheg
    • Okay, then explain your question. Do you want to display 3 records and 3 different ones? LIMIT 3 - solution for 3 entries. Then you answer that in this case you have the same 3 entries. ORDER BY RAND () - sorts the list at random from the records that will satisfy the conditions, and LIMIT 3 will display only the first 3 from this list. Thus, the query I proposed will display 3 random entries from the table table! - Anton Lakotko
    • Again, you did not understand why I need random records ??? I need to display 3 entries with WHERE status = 'top' - Dimcheg
    • 2
      SELECT * FROM table WHERE status = 'top' LIMIT 3; - so advised @ ua6xh - Anton Lakotko