Comparing the two tables

Hello,
Comparing two tables and listing those that are out of sync

Table_1
id----teklif_id
1----15
2----23
3----28
4—33

Table_2
id----teklif_id
1—23
2----33

Output
teklif_id: 15
teklif_id: 28

How can I do that?
I searched but could not understand from what I found

Get all the IDs from each table as arrays in PHP:

$table_1_ids = [15, 23, 28, 33];
$table_2_ids = [23, 33];

You can then use the inbuilt array_diff function to find values in one list but not the other:

$missing_from_table_2 = array_diff($table_1_ids, $table_2_ids);
// $missing_from_table_2 will now be [15, 28]

Thank you for the answer,
Isn’t it possible with direct table query?
Need to get other data in rows that do not match
It is necessary to query 3 times for a job

You want the rows from table 1, where the row is not in table 2:

SELECT teklif_id
FROM table_1
WHERE teklif_id NOT IN (SELECT teklif_id FROM table_2);

That should do it.

1 Like

Why do you have duplicate data in the first place?

I’m trying to do this
The quote has been generated and saved to the table_A
Offers selected products from the Registered Quote AND Saved in the table_B
The manager approves the selected products in the ordered Price Quote AND Saved in the table_C

I want to make a notification in the administration panel

  1. New Price Offers Made
  2. Offered Price Offers Products
  3. Approved Price Offers Products

The above query will list unconfirmed orders
Table_1 => Offers table
Table_2 => Confirmed Offers
List if the Offer is not approved

Thank you very much, I saw this job

Sponsor our Newsletter | Privacy Policy | Terms of Service