![]() |
small php/mysql help needed
i need help on this, can someone please look at this,
let's say there are two tables on my database 1. category table having column id with values like 1 to 10 2. details table having column category with the values like 2, 4, 6, 8, 10 so i want to list 5 values from category table's id columns but only those values that are in details table category column, how do i do it pls guide me. |
Something like this, perhaps?
sql Code:
|
[SQL]
SELECT category.id FROM category, details WHERE category.id = details.category LIMIT 5; [/SQL] or maybe this? |
thank you very much both of this works but i am facing one problem
my details table has some same value in many rows like this 1 1 1 1 10 10 10 4 4 5 5 5 show how can i limit only the the numbers by descending orders instead of limiting the rows |
[CODE=SQL]
SELECT category.id FROM category, details WHERE category.id = details.category ORDER BY category.id DESC; [/code] just add order by `field` desc; or asc for ascending order. ;) |
actually it's like this in my category table there is id column having rows with values like this
1 2 3 4 5 6 7 8 9 10 and in my details table there is category column having rows like this 2 2 2 2 6 6 6 6 4 4 4 8 8 8 10 and i did this PHP Code:
10 8 8 8 6 and that is what i wanted but it's continuing the same value if i don't do LIMIT 5 than it goes like this 10 8 8 8 6 6 6 6 4 4 4 2 2 2 2 all i want is to output like this without repeating any values like 10 8 6 4 2 please help |
Try
Code:
SELECT category.id, category.title, details.category |
| All times are GMT. The time now is 02:34 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0