hyster Posted January 20, 2013 Share Posted January 20, 2013 i have 2 tables tanks list - country - type - name - tier tanks_own player - tanks list and tanks tie both the tables together. what i want to do is search "tanks_own" for a player, get the "tanks" value then search "tanks list" for "tanks_own tanks" result. SELECT * FROM tanks WHERE tanks IN (SELECT * FROM tanks_own WHERE player = 'hyster' Quote Link to comment https://forums.phpfreaks.com/topic/273384-nested-sql-query/ Share on other sites More sharing options...
DavidAM Posted January 20, 2013 Share Posted January 20, 2013 You have not asked a question. However, you want to use a JOIN to do this, using the column that is common between the two tables SELECT list, country, type, name, tier FROM tanks JOIN tanks_own ON tanks.name = tanks_own.tanks WHERE tanks_own.player = 'hyster' (I'm not sure what column in "tanks" matches the column "tanks" in "tanks_own", so I took a guess) P.S. When using IN, the sub-query needs to return a single column: SELECT * FROM tanks WHERE tanks IN (SELECT name FROM tanks_own WHERE player = 'hyster' (But the JOIN is probably more efficient.) Quote Link to comment https://forums.phpfreaks.com/topic/273384-nested-sql-query/#findComment-1407061 Share on other sites More sharing options...
hyster Posted January 20, 2013 Author Share Posted January 20, 2013 cheers david. got what i wanted using SELECT* FROM tanks JOIN tanks_own ON tanks.list = tanks_own.tanks WHERE tanks_own.player ='hyster' LIMIT 0 , 30 i been up since 7am yesterday and not thinking stright and i should use a better layout for my database bt im doing what i need a step at a time thne adding bits asi go lol Quote Link to comment https://forums.phpfreaks.com/topic/273384-nested-sql-query/#findComment-1407064 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.