Ionut Necula
Ionut Necula

Reputation: 11472

How to retrieve results of meta_values by meta_value and meta_key?

I'm trying to SELECT all the meta values from my WP database where meta_value = 'x' and meta_key = 'y'. But my query returns nothing:

SELECT meta_value FROM `tst_postmeta` WHERE meta_key = 'thevoters' AND meta_value = 'mint'

What am I doing wrong here?!

Update

The query should return the meta_value column with some ids based on meta_key called 'the_voters' but also where meta_value equals 'mint'.

I've also tried this query:

SELECT meta_value FROM `tst_postmeta` WHERE meta_key = 'thevoters' AND meta_key = 'sticker_chosen' AND meta_value = 'mint'

Upvotes: 0

Views: 1907

Answers (2)

Peter_James
Peter_James

Reputation: 647

Your SQL is correct, but you have no data in your result set.

Upvotes: 0

Bavard
Bavard

Reputation: 76

From the little information you offered and your query my guess is that no data exists for your query.

Have you tried seeing what shows up when you run

SELECT * 
FROM tst_postmeta

This should show you everything in your table and you can filter by meta key and meta value in your result to see if anything exists for those values.

You can also try breaking down your query into two queries to see if either provides a result, if nothing shows up for either query then there will be no values when you combine them.

SELECT meta_value 
FROM tst_postmeta 
WHERE meta_key = 'thevoters' 

SELECT meta_value 
FROM tst_postmeta 
WHERE meta_value = 'mint'

Upvotes: 1

Related Questions