Title: Validate my SQL?
Last modified: August 18, 2016

---

# Validate my SQL?

 *  [drzax](https://wordpress.org/support/users/drzax/)
 * (@drzax)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/validate-my-sql/)
 * Hi could someone please validate my SQL. I can’t find a problem but it clearly
   isn’t working.
 * “SELECT * FROM $tableposts
    WHERE post_date <= ‘$now’ AND post_status = ‘publish’
   AND ID = ( SELECT post_id FROM wp_postmeta WHERE meta_value = ‘$key’)”
 * Cheers,
    S.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [vinnie](https://wordpress.org/support/users/vinnie/)
 * (@vinnie)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/validate-my-sql/#post-138745)
 * If you’re using an older version of MySQL (i.e. 3.2.3, which a lot of web hosts
   are still running) then you can’t use subqueries.
 *  [GeekNJ](https://wordpress.org/support/users/geeknj/)
 * (@geeknj)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/validate-my-sql/#post-138796)
 * You don’t need a subquery here. The following should work, though it’s done freehand
   and might have a typo:
 * SELECT $tablesposts.* FROM $tableposts, $tablepostmeta
    WHERE post_date <= ‘$
   now’ AND post_status = ‘publish’ AND ID = post_id and meta_value = ‘$key’
 *  Thread Starter [drzax](https://wordpress.org/support/users/drzax/)
 * (@drzax)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/validate-my-sql/#post-138797)
 * Cheers, guys. All sorted.
 * S.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Validate my SQL?’ is closed to new replies.

 * 3 replies
 * 3 participants
 * Last reply from: [drzax](https://wordpress.org/support/users/drzax/)
 * Last activity: [21 years, 2 months ago](https://wordpress.org/support/topic/validate-my-sql/#post-138797)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
