Shadowing Posted September 30, 2012 Share Posted September 30, 2012 Hey guys im trying to select a row from table planets where there are no matches between planet.address and travel.defender_planet I dont think im using inner join correctly at all here i'm thinking when you want a return result it wont work when there are not two columns matching in two tables SELECT planets.address FROM planets LEFT JOIN travel ON planets.address != travel.defender_planet WHERE planets.address != travel.defender_planet LIMIT 1 My end objective is to let me select a row from planets.address where there are no rows in travel table with that address Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 30, 2012 Share Posted September 30, 2012 You're not using an inner join, you're using a left join. Try this. SELECT planets.address FROM planets LEFT JOIN travel ON planets.address = travel.defender_planet WHERE travel.defender_planet IS NULL Quote Link to comment Share on other sites More sharing options...
Shadowing Posted September 30, 2012 Author Share Posted September 30, 2012 oh thanks alot Jessica so it selects the row that comes up Null interesting Quote Link to comment Share on other sites More sharing options...
Shadowing Posted September 30, 2012 Author Share Posted September 30, 2012 what i really wanted to do was use a left join in a update. so im updating the row in the same query and also comparing to make sure the row im selecting isnt matching in the travel table. something like this but syntax is incorrect UPDATE planets SET planets.id = 4005 LEFT JOIN travel ON planets.address = travel.defender_planet WHERE travel.defender_planet IS NULL Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 30, 2012 Share Posted September 30, 2012 What is id? Sounds like something you shouldn't be updating... Quote Link to comment Share on other sites More sharing options...
Shadowing Posted October 1, 2012 Author Share Posted October 1, 2012 (edited) places the players id on the planet to show he owns it This script doesnt get used much maybe i should just do this with two seperate queries Thought it would be kewl if it was combinable. I just started with using joins on my scripts so pretty new to it. Edited October 1, 2012 by Shadowing Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 1, 2012 Share Posted October 1, 2012 Sounds like the field should be named "owner_id" instead of just "id" then, since "id" tends to be the primary key and identifier for each individual record (planets in this case). Which is what Jessica was reacting to. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 1, 2012 Share Posted October 1, 2012 If you're getting a syntax error, post it. That query however will assign that id to EVERY matching row. Which I doubt is what you want. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 3, 2012 Share Posted October 3, 2012 I think yuou had the clauses in the wrong order. Try UPDATE planets LEFT JOIN travel ON planets.address = travel.defender_planet SET planets.id = 4005 WHERE travel.defender_planet IS NULL 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.