$result = mysql_query(" SELECT a.
user_id
, a.user_name
, a.cell_no
, a.internet_package
, a.activation_date
FROM `alepo_data` a LEFT JOIN `".$month2."` c ON c.`user_id` = a.`user_id` WHERE c.`user_id` IS NULL ");
I have a query like above... Here I want to check for $month2. Now If I want to compare $month1 in the same way, then what would be the Query?
Note that, here $month1 or $month2 are SAME TYPE OF TABLE (with Same Table STRUCTURE) just holds different type of usage Data.
Can anyone help me, please?
You can do multiple joins by just adding the join to the ones you already have:
SELECT
a.user_id,
a.user_name,
a.cell_no,
a.internet_package,
a.activation_date
FROM
`alepo_data` a
LEFT JOIN `month1Data` c1 ON c1.`user_id` = a.`user_id`
LEFT JOIN `month2Data` c2 ON c2.`user_id` = a.`user_id`
WHERE
c1.`user_id` IS NULL OR c2.`user_id` IS NULL
Note that, if your tables have the same (or even very similar) table structures, you probably can optimize your table structure. You might be able to fit everything into one table with a 'date' or 'month' column added. If not, you can probably still apply a star schema. If the tables are split because of performance reasons, have a look at table partitioning.