Jefsama Jefsama - 1 year ago 65
SQL Question

Laravel working out with multiple data in a column

I am working on a laravel base profiling system.

Example tables..


id | Name | sports_id
1 | foo | 1,2
2 | bar | 2,3
3 | derp | 1,3


id | Name |
1 | basketball |
2 | volleyball |
3 | swimming |


How can i get all person's name, who's sports are basketball only?

Coz i'm confuse on how to execute the query above due to the
's table is not normalize.


Is there a way to make the person table normalize, so i can query the on it properly?

Answer Source

You should really use many-to-many relationshsip here.

If for some reason you don't want to then use simple query:

User::where('sports_id', 2)->get();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download