MySql SELECT items of a list and their name item stored in another table?
I have to manage lists of items , so i built a table for the lists list_tb
,one item_tb
for the items (same item can be in more lists) and one table item_to_list_tb
for the relation between item and lists
item_tb
and item_to_list_tb
they have in common item_id
list_id
and item_to_list_tb
they have in common list_id
each row of item_tb contain开发者_如何学Gos the name of the product so here i'm trying to get all the items that belong to a list $ID, and their name...i tried this but doesn't work well...
SELECT item_to_list_tb.*, item_tb.*
FROM item_to_list_tb
LEFT JOIN item_tb ON item_tb.item_id = item_tb.item_id
WHERE item_to_list_tb.list_id= $ID
GROUP BY item_tb.item_id
ORDER BY item_to_list_tb.item_ord
bottom line i need to retrieve a bunch of items aong with their name, stored in a different table...
whats the best practice? thanks!
Try something like:
SELECT item_tb.* FROM item_tb LEFT JOIN item_to_list_tb USING (item_id) WHERE item_to_list_db.list_id=$i
精彩评论