nezbie Posted June 11, 2007 Share Posted June 11, 2007 Hi I have a table consisting of following data: id name languages_id None of those fields are unique, so one id can have multiple languages_id's.. My problem is, that I'd need to select all id's from the table where languages_id has a value of x, but not y.. So the idea in php is to copy all the fields to language y if it does not exists.. Example: id name languages_id 10 frontpage 1 10 startseite 2 20 information 1 id 20 does not exists in german (languages_id = 2), select this id. I've tried like (as simple as I thought it COULD be.. wasn't): SELECT DISTINCT id FROM table WHERE languages_id = "1" AND languages_id != "2" I'll try to work this out Quote Link to comment https://forums.phpfreaks.com/topic/55078-solved-selecting-and-ignoring-issue-plz-help/ Share on other sites More sharing options...
Illusion Posted June 11, 2007 Share Posted June 11, 2007 try this SELECT DISTINCT id FROM table WHERE languages_id = "1" AND id NOT IN (SELECT DISTINCT id FROM table WHERE languages_id = "2" tell me is it working fine or you got any syntax error. Quote Link to comment https://forums.phpfreaks.com/topic/55078-solved-selecting-and-ignoring-issue-plz-help/#findComment-272276 Share on other sites More sharing options...
fenway Posted June 11, 2007 Share Posted June 11, 2007 A self join would work too... Quote Link to comment https://forums.phpfreaks.com/topic/55078-solved-selecting-and-ignoring-issue-plz-help/#findComment-272416 Share on other sites More sharing options...
nezbie Posted June 11, 2007 Author Share Posted June 11, 2007 SELECT DISTINCT id FROM table WHERE languages_id = "1" AND id NOT IN (SELECT DISTINCT id FROM table WHERE languages_id = "2") works fine - thanx for both answer, really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/55078-solved-selecting-and-ignoring-issue-plz-help/#findComment-272528 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.