Skip to content
Advertisement

PHP MysqlI – How to Select 1 Row? (from select)

I am a bit stumped on how i should be able to Define 1 post ID, and only select from that row my query:

JavaScript

my end goal is to get all from row 3 (only row 3), not get all rows. when i run the query above, i get every row from mysql.

example:

JavaScript

returns with all rows,

what i need to do is just return the 3rd row (from the post_id, and only that row)

JavaScript
JavaScript

final edit, i kinda just said screw it and just did this:

JavaScript

thanks to all who helped though, i really appreciate it.

Advertisement

Answer

You can use the function ROW_NUMBER() (MySQL 8 MariaDB 10.4)

The principal thing is, that MySQL needs an order to determine which row number is what

I selected

JavaScript

But it can be every column from the from clause

JavaScript
JavaScript
JavaScript
JavaScript
post_id | title                                    | likes | liked
------: | :--------------------------------------- | ----: | :----
      3 | Ajax Jquery Column Sort with PHP & MySql |     0 |      
JavaScript
post_id | title                                    | likes | liked
------: | :--------------------------------------- | ----: | :----
      3 | Ajax Jquery Column Sort with PHP & MySql |     0 |      

db<>fiddle here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement