[英]PHP MySQL Query to Match dynamic field value with other fields dynamic match value condition based
以下是我在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
將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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.