I need help with an equation that I’m trying to resolve here. I need to construct a query that would output the result highlighted with RED given the url value highlighted with BLUE, using the “name1” match from field_one as a reference.
SELECT value2.field_two
FROM table_name as value1
LEFT JOIN table_name AS value2 ON (REPLACE(value1.field_one, ‘_url’, ‘’) = REPLACE(value2.field_one, ‘_num’, ‘’))
WHERE value1.field_two = ‘http://siteY.com’
Hi r937, thanks for being so responsive as usual. It’s a WordPress query, I’m trying to play with values inside the “wp_postmeta” table, and I got it to work, thanks!
Ok, I’m using the Advanced Custom Fields plugin together with the Repeater add-on for a client licensing platform. Licenses are per domain, so I’m storing sets of “Domain Name” + “Expiry Date” user meta values in the database. Now, to be able to check if we’re past an expiry date I had to use the following formula (assuming that ACF is storing the data as follows:
My goal was to check the expiry date of any given license by the domain name with just one sql query which I managed to work out soon after posting this thread (I wish it also were an optimal way of doing it, please correct me if wrong):
SELECT domain.user_id
FROM $wpdb->usermeta as domain
LEFT JOIN $wpdb->usermeta AS expiry ON ( REPLACE( domain.meta_key, '_domain', '' ) = REPLACE( expiry.meta_key, '_expiry', '' ))
WHERE domain.meta_value = '$domain'
AND expiry.meta_value > UNIX_TIMESTAMP(NOW())
It was my understanding that by simplifying the variables, a solution would be easier to work on, will keep your note in mind though
An INNER JOIN will retrieve all records from both tables that have matching values for whatever column you’re joining them on. Records from either table that don’t match will not be retrieved. A LEFT JOIN will retrieve all records from the left (first) table, and only the records from the second table with matching values for the joining column, filling in any empty spaces with NULL values.
Great, so I does look like I need INNER JOIN indeed, thanks again!