I am new to sql and went through alot of discussion and youtube but i get more confused.
I was using SELECT * FROM tp_posts to list number of posts into my website so basically below is how my table looks like.
table name tp_posts
==========================================
| ID | post | tp_product
=================================================
| 1 | toyota 1 | toyota
| 2 | mercedez 1 | mercedez
| 3 | bmw 1 | bmw
| 4 | toyota 2 | toyota
| 5 | toyota 3 | toyota
| 6 | toyota 4 | toyota
==========================================
Above table is example on how it looks as you can see it will show all the i items above if i use the normal query i mentioned above so i started using this
SELECT * FROM tp_posts GROUP BY tp_product
this works but it only shows the first toyota post and hide the latest ones and order by is not working also as group by hide the other posts
I want to display the latest post while filtering related posts that share the same tp_product column, it has to show the last toyota post from above table
table name tp_posts
========================================================
| ID | post | tp_product post_numb
========================================================
| 1 | toyota 1 | toyota | 1
| 2 | mercedez 1 | mercedez | 1
| 3 | bmw 1 | bmw | 1
| 4 | toyota 2 | toyota | 2
| 5 | toyota 3 | toyota | 3
| 6 | toyota 4 | toyota | 4
==========================================
Update This is the complete table now as you can see above post section and post_num are related on post it shows toyota 1 tp_product which is product type = toyota and post_numb = 1 which represents toyota 1 in posts section.
Some people suggested i use order by but it doesn't work like that as i get all posts in table either way i want to get the result that look like this table below
table name tp_posts
========================================================
| ID | post | tp_product post_numb
========================================================
| 6 | toyota 4 | toyota | 4
| 3 | bmw 1 | bmw | 1
| 2 | mercedez 1 | mercedez | 1
======================================================
I want to get The above results in my query, sorry if i was not clear enough Thanks