I have 2 tables A and b namely.
Table A has
+------+---------------+
|MANUID|LMD |
+------+---------------+
|1,001 |10/18/2013 7:13|
+------+---------------+
|1,001 |10/18/2013 7:13|
+------+---------------+
|1,001 |10/18/2013 7:13|
+------+---------------+
|1,001 |10/18/2013 7:13|
+------+---------------+
|1,001 |10/18/2013 7:13|
+------+---------------+
|1,001 |10/18/2013 7:13|
+------+---------------+
|1,001 |10/18/2013 7:13|
+------+---------------+
Table B has
+------+---------------------------------+
|MANUID|MANUFACTURERDESC |
+------+---------------------------------+
|1,001 |ACTION CONSTRUCTION EQUIPMENT LTD|
+------+---------------------------------+
|1,002 |AJAX FIORI ENGG (INDIA) PVT LTD |
+------+---------------------------------+
|1,003 |APOLLO CONST. EQUIPMENT PVT LTD |
+------+---------------------------------+
|1,004 |APOLLO INDUSTRIAL EQUIP. PVT LTD|
+------+---------------------------------+
|1,006 |ASHOK LEYLAND |
+------+---------------------------------+
|1,007 |ATUL AUTO LTD |
+------+---------------------------------+
|1,009 |ATLAS COPCO INDIA LTD |
+------+---------------------------------+
I want to remove MANUID from Table B which is not available in Table A.
So from above my final Table B will be has only 1,001 in MANUID
SELECT * FROM Table_B
WHERE MANUID IN
(SELECT MANUID FROM Table_A)
OR
SELECT * FROM Table_B
JOIN Table_A ON Table_B.MANUID = Table_A.MANUID
Or if you want to delete records:
DELETE * FROM Table_B
WHERE MANUID NOT IN
(SELECT MANUID FROM Table_A)
Answer:
If you are using SQL query Try this:
select tb.*
from Table B as tb, Table A as ta
where tb.MANUID = ta.MANUID
Answer:
You can SELECT
them with an INNER JOIN
:
SELECT * FROM TableA ta
INNER JOIN TableB tb ON ta.MANUID = tb.MANUID
INNER JOIN
will only select the records from TableB where the MANUID
field matches those of TableA.
And then DELETE
them :
DELETE FROM TableB
WHERE MANUID NOT IN (SELECT MANUID FROM Table_A)
Answer:
You should use VLOOKUP function, here’s help:
http://office.microsoft.com/en-us/excel-help/vlookup-HP005209335.aspx
(I assume table A starts at cell A1 and table B starts at cell A11)
In the third column in table B you should write:
=vlookup(A11;A2:B8;2;0)
It will say: 1,001
If you copy the formula a row under you will see “N/A” appears.
Every rows with “N/A” should be dropped, because it means that you can’t find that value in table A.
(Please notice that excel changes the referred cells when you copy the formula, for that you can use a dollar sign, here’s help: http://www.notjustnumbers.co.uk/2011/05/excel-tip-dollar-sign-in-formula-fixing.html)
Tags: excel, mysqlmysql, sed, sql