主查询语句外的子选择语句

时间:2017-03-20 08:21:41

标签: php mysqli

答案可能是盯着我的脸,但我不能为我的生活弄清楚,所以我有这个

"SELECT count(*), template_name, sent, date_inserted, ln_project_id, project_name 
    FROM mailer_events
    INNER JOIN ln_mailer_events 
    USING ( mailer_event_id ) 
    LEFT OUTER JOIN ln_logs 
    USING ( ln_log_id ) 
    INNER JOIN ln_actions 
    USING ( ln_action_id ) 
    inner join ln_projects 
    using (ln_project_id) 
    inner join mailer_templates 
    using ( mailer_template_id)

    WHERE {$idorname} = '{$p_id}' 
    and sent > '{$sent_date_string}' and mailer_drip_id =0 
    group by mailer_template_id"; 

这是我的主查询,如果我的搜索是数字,它会响应。问题我想要一个不同的select语句,如果它的文本或字符串使用主查询的答案,如:

"SELECT ln_project_id from ln_projects where project_name = `{$p_id}`";

但这不起作用。

1 个答案:

答案 0 :(得分:1)

使用LIKE运营商:

$query = "SELECT ln_project_id from ln_projects where project_name LIKE '%". 
$some_text_variable."%' ";