用于高级搜索的php sql查询
我需要为高级搜索执行特定查询 我提供了一个db结构的示例 id code content id_post -------- -------- ----------- ------------- 1 reg lazio 1 2 reg lazio 2 3 type typeX 1 4 type typeY 2 id代码内容id\U post -------- -------- ----------- ------------- 拉齐奥1号 拉齐奥2号 3型typeX 1 4类型Y 2 现在,我必须在此表中进行一些搜索并获得正确的id\u帖子,例如: 我想要所有代码为reg,内容为typeY的id_帖子 在这种情况下没有结果 2d示例-->所有id_帖子,代码=reg,内容=lazio 结果必须是1和2 3d示例-->所有id_post带有(code=reg,content=lazio)和(code=type,content=typeY) 结果必须是2 等等 如何设置这三个查询?尝试以下操作: 例1:用于高级搜索的php sql查询,php,mysql,sql,Php,Mysql,Sql,我需要为高级搜索执行特定查询 我提供了一个db结构的示例 id code content id_post -------- -------- ----------- ------------- 1 reg lazio 1 2 reg lazio 2 3 type typeX 1 4
select id_post from your_table where code = 'reg' and content = 'typeY'
例2:
select id_post from your_table where code = 'reg' and content = 'lazio'
例3:
select t1.id_post from your_table as t1
inner join (select id_post from your_table where code = 'type' and content = 'typeY') as t2 on t1.id_post = t2.id_post
where t1.code = 'reg' and t1.content = 'lazio'
我已经运行了测试来验证结果。你可以自己在这上面验证
示例3基本上是一个示例,这就是为什么
和以及或方法都不起作用的原因。您可以参考以了解解决此类查询的进一步方法。问题到底是什么?查询的结构是自己编写的,如果不起作用,请向我们具体说明您所做的工作,以便我们能够帮助您。你开始,我们帮助。我们不是为你写的。向我们展示您尝试过的实际代码,然后我们可以从中帮助您。如果你先亲自尝试的话,很可能你会非常接近答案。所以我添加了一些join foreach搜索词?在这个例子中,我只使用了2个查询,但如果有3、4、5等。。。查询次数?例如:谢谢克劳斯·比斯科夫·彼得森,你救了我一天。谢谢;-)