So I have been searching through ways to get this to operate and weren't capable of finding it, or really even correctly search.

I am searching to become listed on t1 to t2 where I recieve ALL is a result of t1, and it is only became a member of where t2's column value is "something", the table is to establish that you will find many products within the t2 column. Therefore if t2's column does not equal "something", then simply have another data (but mainly I only have to have one of every value for t1 row, because you will see a max of 1 t2 row that qualifies per t1 row).

select * t1 LEFT JOIN t2 where t2.column="something" AND t1 conditions.

Any help could be appreciated, the tables are WordPress tables, and the one thing I am requested to complete could be simpler done without WordPress knowing.

-- Actual code attempt:

$ SELECT * FROM posts LEFT JOIN postmeta ON post_id = id WHERE post_status='publish' AND post_type='portfolio' AND meta_key='rjmeta_video'

$Table 1
$ID     Title ....
$5      Some post I need outside of WP

$Table 2
$meta_id  post_id   meta_key  ....
$3        5         rjmeta_video
$4        5         _edit_lock
$5        5         _edit_last

In my opinion this is exactly what you mean:

select distinct t1.* from t1 
LEFT JOIN t2 on [condition for join] and t2.column="something" 
where [t1 conditions].

This assumes that you're only thinking about the t1 fields.

What we should have no idea:

  • table schemas
    • how could they be became a member of? t2.t1_id = ?
  • t1 conditions

DISTINCT used above will eliminate duplicate rows if you will find multiple matches for that join

EDIT (OP comment response):

SELECT distinct posts.* FROM posts 
LEFT JOIN postmeta ON (post_id = id and meta_key='rjmeta_video')
WHERE post_status='publish' AND post_type='portfolio'

This assumes that 'rjmeta_video' may be the "something" you had been mentioning to initially