I want to write a query that return only value after the last one on table
I have 2 tables with same fields but Table A has more data than Table B.
I want to write a query that returns the data that not in table B. there is a lot of rows on both table.
and there is a field with incremental value as Key value on both tables.
can anyone help me with this?
I'm not good with queries
Hi ahmeds08
there is a column with numbers from 1 ... etc.
can i use this column to know what rows aren't in table B?
it will be the rows after the last number of this column in table B
INSERT INTO logicI.dbo.ACCOUNTENTRY(ACCOUNTINGCURRENCYAMOUNT,LEDGERACCOUNT,RECID) SELECT * FROM logicI.dbo.ACCOUNTENTRY WHERE recid NOT IN (SELECT recid FROM DLive.dbo.ACCOUNTENTRY)
Always mention column list and avoid using select *
can you try this
INSERT INTO logicI.dbo.ACCOUNTENTRY(ACCOUNTINGCURRENCYAMOUNT,LEDGERACCOUNT,RECID)
SELECT ACCOUNTINGCURRENCYAMOUNT,LEDGERACCOUNT,RECID FROM DLive.dbo.ACCOUNTENTRY
WHERE recid NOT IN
(SELECT recid FROM logicI.dbo.ACCOUNTENTRY )
thanks a lot ahmed,
this was really helpful and did exactly what I wanted,
just one more thing,
can I use nolock with this query? could you show me please?
just to be safe.
thanks again
INSERT INTO logicI.dbo.ACCOUNTENTRY(ACCOUNTINGCURRENCYAMOUNT,LEDGERACCOUNT,RECID)
SELECT ACCOUNTINGCURRENCYAMOUNT,LEDGERACCOUNT,RECID FROM DLive.dbo.ACCOUNTENTRY WITH (NOLOCK)
WHERE recid NOT IN
(SELECT recid FROM logicI.dbo.ACCOUNTENTRY WITH(NOLOCK))