Jump to content

nested sql query


hyster

Recommended Posts

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'

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.