How can i add two WHERE statement in MySQL Query?

Obada Diab

I have this query of MySQL,

return $this->resultQuery("SELECT COUNT(home_id) AS total 
    FROM `".$this->table_prefix."user_homes` 
    WHERE user_id = $assign_id ". 
    ($home_cfg_id ? 'AND `home_cfg_id` IN (
        SELECT `home_cfg_id` 
        FROM `'.$this->table_prefix.'server_homes` 
        WHERE home_cfg_id = '.$home_cfg_id' )': ''));

but still got error when i run this query

RToyo

As requested, I'm putting this in an answer. You are missing a concatenating . at the end of your query string, after $home_cfg_id.

When debugging something like this, it is often helpful to do as @xQbert suggested, and output the sql string. This will allow you to review the query for anything that looks wrong - as well as (possibly) give a clearer PHP error if the string is created incorrectly.

return $this->resultQuery("SELECT COUNT(home_id) AS total 
    FROM `".$this->table_prefix."user_homes` 
    WHERE user_id = $assign_id ". 
    ($home_cfg_id ? 'AND `home_cfg_id` IN (
        SELECT `home_cfg_id` 
        FROM `'.$this->table_prefix.'server_homes` 
        WHERE home_cfg_id = '.$home_cfg_id.' )': ''));
                                          ^

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to create IF statement in MYSQL query WHERE statement

From Dev

how can use two where in one column with mysql join query?

From Dev

How Can i write update statement in mysql with select query?

From Dev

How can I use two where clauses in a SQL query

From Dev

How can I add a WHERE condition on a Text field in a SQLite query?

From Dev

How can I add selective rows in a Mysql statement

From Dev

How can I add a break line in the where condition in MySQL?

From Dev

How can I connect two different views in mysql query

From Dev

MySQL-Statement. How do i skip rows in query where all rows equal null

From Dev

How can I speed up this MySQL Query where the WHERE clauses are already indexed?

From Dev

How can I check two conditions in an if statement?

From Dev

How I can divide two statement in PHP

From Dev

MySQL query slow on where statement

From Dev

Based on the following MYSQL query how can I write an UPDATE statement to update a value?

From Dev

How to get if else statement in mysql query in WHERE clause?

From Dev

How can I do a LINQ query joining two entities and select what a Where on one of the entities?

From Dev

How can I use OR statement in mysql php

From Dev

How can I use where with two condition

From Dev

How can I conditionally add where clauses and filter children in a single linq query?

From Dev

How do I add two arrays together and collect ids where one or both can be null

From Dev

How can I add Multiple WHERE condtions

From Dev

How can I add Multiple WHERE condtions

From Dev

How can I add a where condition in SSRS?

From Dev

how can i query all records in mysql where field is not empty or null?

From Dev

Can I conditionally add a where() clause to my knex query?

From Dev

How can I Join Two Query

From Dev

how to add two IDs in where condition in joomla query?

From Dev

How can can I combine two IF statement in Excel?

From Dev

How can I add two videos in PlyrJS

Related Related

  1. 1

    How to create IF statement in MYSQL query WHERE statement

  2. 2

    how can use two where in one column with mysql join query?

  3. 3

    How Can i write update statement in mysql with select query?

  4. 4

    How can I use two where clauses in a SQL query

  5. 5

    How can I add a WHERE condition on a Text field in a SQLite query?

  6. 6

    How can I add selective rows in a Mysql statement

  7. 7

    How can I add a break line in the where condition in MySQL?

  8. 8

    How can I connect two different views in mysql query

  9. 9

    MySQL-Statement. How do i skip rows in query where all rows equal null

  10. 10

    How can I speed up this MySQL Query where the WHERE clauses are already indexed?

  11. 11

    How can I check two conditions in an if statement?

  12. 12

    How I can divide two statement in PHP

  13. 13

    MySQL query slow on where statement

  14. 14

    Based on the following MYSQL query how can I write an UPDATE statement to update a value?

  15. 15

    How to get if else statement in mysql query in WHERE clause?

  16. 16

    How can I do a LINQ query joining two entities and select what a Where on one of the entities?

  17. 17

    How can I use OR statement in mysql php

  18. 18

    How can I use where with two condition

  19. 19

    How can I conditionally add where clauses and filter children in a single linq query?

  20. 20

    How do I add two arrays together and collect ids where one or both can be null

  21. 21

    How can I add Multiple WHERE condtions

  22. 22

    How can I add Multiple WHERE condtions

  23. 23

    How can I add a where condition in SSRS?

  24. 24

    how can i query all records in mysql where field is not empty or null?

  25. 25

    Can I conditionally add a where() clause to my knex query?

  26. 26

    How can I Join Two Query

  27. 27

    how to add two IDs in where condition in joomla query?

  28. 28

    How can can I combine two IF statement in Excel?

  29. 29

    How can I add two videos in PlyrJS

HotTag

Archive