here is my query
SELECT con_serial,column2,column3
FROM
(SELECT con_serial,column2,column3
FROM big_table
WHERE ISNULL(contact1, '')+'#'+ISNULL(contact2, '')+'#'+ISNULL(contact3, '')+'#'+ISNULL(contact4, '')+'#'+ISNULL(contact5, '')
LIKE '%' + '".$conserial."' + '%') AS a
WHERE con_serial
IN('".$contact1."','".$contact2."','".$contact3."','".$contact4."','".$contact5."')
at the inner select i wish to get the rows which have this value $conserial
in one of their 5 columns(contact1...contact5)
and the outer select to choose the rows from it that their column con_serial
is one of the variables ($contact1...$contact5)
can anybody see what's wrong here?
Despite your new formulation, it remains very much unclear.
Nevertheless I'll try to give you an answer, based on what I can guess...
First here is how I'd reformulate your need:
$conserial
and five $contact#
where #
is 1-5con_serial
, column2
, column3
, and five contact#
where #
is 1-5contact#
columns matches the PHP $conserial
valuecon_serial
column matches at least one of the PHP $contact#
valuesThat said, note that you don't need to have two nested SELECT
: you only want each row to satisfy two conditions, so they can be ANDed in the WHERE
clause.
Based on that, your query should be:
$query = "
SELECT con_serial, column2, column3
FROM big_table
WHERE con_serial IN ('$contact1', '$contact2', '$contact3', '$contact4', '$contact5')
AND '$con_serial' IN (contact1, contact2, contact3, contact4, contact5)
";