[PHP] sql syntax problem
Hello everybody, I am trying to create a sql query with php and I do have a syntax problem with the mysql query. One row is called plz and I would like to search for a value inside that with a like statement. Problem is, the system takes the u.plz as a character not as a table element: LIKE %u.plz% Has anybody an idea how the correct sytnax is? I am lost here. Thank you in advance, Merlin PS: This is the complete statement: SELECT c.name AS city FROM geo_de.geodb_locations AS c, fix.user AS u WHERE u.user_id =4 AND c.plz LIKE %u.plz%; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sql syntax problem
Merlin wrote: SELECT c.name AS city FROM geo_de.geodb_locations AS c, fix.user AS u WHERE u.user_id =4 AND c.plz LIKE %u.plz%; I believe you want something not unlike this: WHERE u.user_id = 4 AND c.plz LIKE concat('%', u.plz, '%') -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sql syntax problem
This is the PHP mailing list, not the SQL mailing list ;) but here is the syntax ( not tested ): SELECT c.name AS city FROM geodb_locations AS c, user AS u WHERE u.user_id = 4 AND c.plz LIKE u.plz; Hello everybody, I am trying to create a sql query with php and I do have a syntax problem with the mysql query. One row is called plz and I would like to search for a value inside that with a like statement. Problem is, the system takes the u.plz as a character not as a table element: LIKE %u.plz% Has anybody an idea how the correct sytnax is? I am lost here. Thank you in advance, Merlin PS: This is the complete statement: SELECT c.name AS city FROM geo_de.geodb_locations AS c, fix.user AS u WHERE u.user_id =4 AND c.plz LIKE %u.plz%; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php