Ideally, you should do it in pure SQL, suck with PHP without it.
Let's say your table A is an integer and table column B int . If you can do something like this: temporary table X Create, Connect with A B A = B. B; Remove from B where in B (choose from X); Remove from A (choose one from X); Put in A (A) (choose B to B); It does the following:
- Creates a temporary table and enter all records that are present in both A and B
deletes all records in both tables < table X temporary Designed to be built, it will be automatically deleted when the database connection stops.
Now, if you have to call it with PHP, you can do the following: $ db = new PDO ($ CONNECT_STRING, USERNAME, password); $ Db- & gt; Choose from the joining on exec ("a.b. b." to create temporary table X); $ Db- & gt; exec ("Remove from B where in B (choose one from x)"); $ Db- & gt; exec ("Remove from A where one (choose from x)"); $ Db- & gt; Exec ("Select from B" (B) "); $ db = null; Edit: If you need all, then from B There are no records that are not present in A, you can do it like a simple SQL:
Select b from where b is not (select A from A)
Comments
Post a Comment