以下是我在MySQL中的数据库表结构-我要按如下所述相互匹配特定的动态字段值:
meta_id post_id meta_key meta_value
616 472 "machine_type" "Combined pipe cutting"
561 472 _edit_lock 1354882015:1
560 472 _edit_last 1
562 472 _mf_write_panel_id 1
565 472 _wp_page_template machine_layout.php
617 472 jet_filter
618 472 "length_x_axis" "3000mm"
619 472 machine_image 488
在上面的
""
引号中标记了字段-我必须针对这些字段应用查询并获取结果。现在在这里,我要检查
meta_key
字段和meta_value
字段,并想检索匹配的post_id
字段的值。例如:我在
meta_key
上的第一个参数将是length_x_axis
,其在meta_value
中的匹配值将是3000mm
,并且AND
条件,在meta_key
中它将是machine_type
,在meta_value
中其匹配值cc>将为Combined pipe cutting
。我需要的结果是
post_id
值472
这是一个完整的动态wordpress
wp_postmeta
表,其中将包含许多条件类似的记录。最早的MySQL查询结果将不胜感激。
如果有任何拼写错误,请原谅我,我已尽力向社区解释我的问题。
请帮忙 !
最佳答案
我不确定您真正想要的是什么,但是我认为这是您要查找的查询:
SELECT t1.post_id
FROM mytable t1 inner join mytable t2 on t1.post_id = t2.post_id
WHERE t1.meta_key = "length_x_axis" and t1.meta_value="3000mm"
AND t2.meta_key="machine_type" and t2.meta_value="Combined pipe cutting"