hackalive Posted August 23, 2013 Share Posted August 23, 2013 Hi guys, I have two mysqli tables (people and data) People has their id and data has the people_id now I need to run a SELECT against data for a select 100 people based on a condition within people (so run a select on people first to get the id, then run the id against data). What is the best and most efficient way to do this? TBL_PEOPLE people_id name age TBL_DATA data_id people_id info So say I want all the info for people aged 50. First I run a select on TBL_PEOPLE to get all the people_id for age = 50. Then need to get info for all people_id results. Hope that all makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/281492-large-where-select/ Share on other sites More sharing options...
Solution gristoi Posted August 23, 2013 Solution Share Posted August 23, 2013 you dont need 2 queries, have a google on using mysql joins: this should get you started: SELECT p.people_id, p.name, p.age, d.data_id, d.info FROM TBL_PEOPLE p INNER JOIN TBL_DATA d USING (people_id) WHERE p.age = 50; Quote Link to comment https://forums.phpfreaks.com/topic/281492-large-where-select/#findComment-1446442 Share on other sites More sharing options...
hackalive Posted August 23, 2013 Author Share Posted August 23, 2013 Thanks for that. I will look into it Quote Link to comment https://forums.phpfreaks.com/topic/281492-large-where-select/#findComment-1446444 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.