Jump to content

Apply set of data to another table


Cultureshock

Recommended Posts

How might I take a set of data from table 1 and apply it to table 2?

For instance.

Table 1:

id*, name, age

Table 2:

id, pet

 

How would I be able to view all the pets of people who are 18 (if 'id' is unique in table 1 and shared by all the pets owned by that person in table 2)?

 

does that make sense? >.<

Link to comment
https://forums.phpfreaks.com/topic/182186-apply-set-of-data-to-another-table/
Share on other sites

For your example, combined with premiso's, you could retrieve the information like this...

 

SELECT * FROM table1
INNER JOIN table2
ON table1.id = table2.personid
WHERE table1.age = 18

 

That SHOULD give you results you expect after you've renamed the table names. It's been a while since I've had to work with SQL (embarrassingly enough), so my knowledge of these things could be a bit rusty, but you get the general idea - joins are your friend.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.