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? Quote Link to comment 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'"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.