Skip to content
Advertisement

how do you fetch data in MYSQL foreign key?

I want to fetch all categories in item table that is equal to the categories in request table of a specific user

example a user requests an item with a category of “math”, i want to fetch all items in item table with category of “math”

Advertisement

Answer

You can do this with joins:

The logic is select all requests of the given user id, and bring the corresponding items. You can then join one more time for items that belong to the same category.

Depending on your data, this might generate duplicates. If so, exists is probably more appropriate:

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