但是你可以使用一个或多个OR来构建一个冗长而复杂的查询。 tblSuppliers(简化) sID | sName 1 | comp name 2 |公司2 tblGoods(简体) gID | gName 1 |鱼 2 |面包 3 |苹果 4 |香蕉 5 |巧克力 tblRefs sID | gID 1 | 1 1 | 2 1 | 3 1 | 4 1 | 5 2 | 2 2 | 4 当你想要一些东西时,你就加入了这些桌子 http://dev.mysql.com/doc/mysql/en/join.html SELECT tblSuppliers.sName FROM tblSuppliers WHERE tblSuppliers .sID = tblRefs.sID和tblRefs.sID =''2''; 或者如果你搜索多个,说巧克力和香蕉 SELECT tblSuppliers.sName FROM tblSuppliers WHERE tblSuppliers.sID = tblRefs.sID AND tblRefs.sID IN(4,5); // Aho You usually build 3 tables tblSuppliers (simplified) sID | sName 1 | comp name 2 | company 2 tblGoods (simplified) gID | gName 1 | fish 2 | bread 3 | apples 4 | bananas 5 | chocolate tblRefs sID | gID 1 | 1 1 | 2 1 | 3 1 | 4 1 | 5 2 | 2 2 | 4 You then join the tables when you want something out of them http://dev.mysql.com/doc/mysql/en/join.html SELECT tblSuppliers.sName FROM tblSuppliers WHERE tblSuppliers.sID = tblRefs.sID AND tblRefs.sID=''2''; or if you search for more than one, say chocolate and bananas SELECT tblSuppliers.sName FROM tblSuppliers WHERE tblSuppliers.sID = tblRefs.sID AND tblRefs.sID IN(4,5); //Aho 在表中的同一个字段中有多个数据是一个不好的想法,原因是BAD 的想法你正在发现将每个条目放在 单独的行上,或者更好(为了避免重复sName),安排 你的数据库如下: tblSuppliers:sID,sName tblSupplierGoods:sID,gID tblGoods:gID,gName 即每家公司在tblSuppliers中有一个条目,将其名称与 ID相关联,然后在tblSupplierGoods中为每个单独的商品ID 提供一个条目。 要查找哪些制造商提供面包,您的查询将是: SELECT tblSuppliers。* FROM tblSuppliers ,tblSupplierGoods,tblGoods WHERE tblSupplierGoods.sID = tblSuppliers.sID AND tblSupplierGoods.gID = tblGoods.gID AND tblGoods.gName =''bread'' - Oli Having multiple pieces of data in the same field in a table is a BADidea, for reasons that you are discovering. Have each entry on aseparate line, or even better (to avoid duplication of sName), arrangeyour db as so: tblSuppliers: sID, sName tblSupplierGoods: sID, gID tblGoods: gID, gName i.e. each company has ONE entry in tblSuppliers linking their name to anID, and then an entry in tblSupplierGoods for each individual goods IDthat they supply. To find which manufacturers supply bread, your query would be: SELECT tblSuppliers.* FROMtblSuppliers, tblSupplierGoods, tblGoodsWHEREtblSupplierGoods.sID = tblSuppliers.sIDAND tblSupplierGoods.gID = tblGoods.gIDAND tblGoods.gName = ''bread''--Oli 这篇关于搜索withina逗号分隔列表(这可能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 11:32