claudiofranck Posted May 10, 2007 Share Posted May 10, 2007 Mysql version 5.0.37 Table: 'refsub', 'CREATE TABLE `refsub` ( `PROJET` char(10) NOT NULL, `SUBSECTO` char(10) NOT NULL, UNIQUE KEY `K_REFSUB` (`PROJET`,`SUBSECTO`), KEY `PROJET` (`PROJET`), KEY `SUBSECTO` (`SUBSECTO`), CONSTRAINT `FK_REFSUB_REFCHIF` FOREIGN KEY (`PROJET`) REFERENCES `refchif` (`PROJET`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_REFSUB_SUBSECTO` FOREIGN KEY (`SUBSECTO`) REFERENCES `subsecto` (`SUBSECTO`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8' This a table that basicaly links a project number with the sector it is invlved with so I only store the primary keys of each, a project can have multiple sectors and of course a sector can belong to multple projects. What I need to do is basically get projects numbers that have 2 or more of the sectors, i.e. prject 1234 had electric and mechanic sectors, project 4567 had also electric and mechanic and maybe others I want to search all projects that have mechanic and electric sectors SELECT * FROM refsub where subsecto like 'electric' and subsecto like 'mechanic'; This query returns no results, using 'or' works, 'and' get's me nothing. Any ideas? Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/50868-help-on-this-query/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 11, 2007 Share Posted May 11, 2007 The one column in one record is never going to have two differenent values and hence will never return a record the following query: SELECT * FROM table WHERE column = 'ValueOne' AND column = 'ValueTwo' # will never return a record - impossible request Quote Link to comment https://forums.phpfreaks.com/topic/50868-help-on-this-query/#findComment-250241 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.