mabus Posted September 8, 2008 Share Posted September 8, 2008 I have 2 tables, say, "Person" and "Hobbies". Person can have zero or more hobbies. Here's what the table structure looks like: Person (Id , Name) Hobbies (Id, PersonId, HobbyName) How do I get all the Person->Id where Person->Name is, say, 'John' regardless if the record has a hobby? Link to comment https://forums.phpfreaks.com/topic/123216-need-help-with-sql-query/ Share on other sites More sharing options...
JasonLewis Posted September 8, 2008 Share Posted September 8, 2008 Well you'd need to use a JOIN of some sort. Now I'm not to flash with MySQL syntax but here is a shot at it: mysql_query("SELECT * FROM Person AS p JOIN Hobbies AS h ON p.Id=h.PersonId WHERE p.Name='John'"); Link to comment https://forums.phpfreaks.com/topic/123216-need-help-with-sql-query/#findComment-636356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.