SQL Help ?!?!

Pho3nix

The Legend
Joined
Jul 31, 2009
Messages
32,826
Reaction score
3,033
Location
On the toilet
Hi guys,

Need help with a query on SQL. Need to import all the rows from Column B into Column A, aslong as they aren't already there. Tried UPDATE but it is not working. Any pointers?
Just started learning..
 
Update tablename set columna=columnb where culumna<>columnb

Sent from my GT-P7500 using MyBroadband Android App
 
Tried it but still no luck :(, and have 500 entries to put in...really not looking forward to the Insert Method :(

Update tablename set columna=columnb where culumna<>columnb
Evern tried
Update tablename set columna=columnb where culumna!=columnb
 
Running the queries direct from SQL Server management Studio so I'm pretty sure I'm connected to the database :?
 
If they're already in A then just ignore the where clause

Code:
UPDATE [Table] SET ColA = ColB
 
and you are sure that you haven't already updated the table? That query will only work once.

My understanding is that you want you data to look like this?

Before:
ColumnA ColumnB
x y
x y
x y

After:
ColumnA ColumnB
y y
y y
y y
 
No error, just that no new rows are added.

UPDATE will not add new rows - it will update existing ones. I just tried this in mysql with a table with 10 rows, five of which had a != b:

UPDATE `colacolb` SET `cola`=`colb` WHERE `cola`<>`colb`

It fixed the five != rows without issue.
 
You guys are misunderstanding him and my SQL's slightly rusty.

He has the following:
A B
X X
Y Z

The output should be as follows:
A B
X X
Y Z
Z
 
You guys are misunderstanding him and my SQL's slightly rusty.

He has the following:
A B
X X
Y Z

The output should be as follows:
A B
X X
Y Z
Z
For this you can try
Insert into <Table> (<cola>)
Select Distinct <Colb> from <table>
where <ColB> NOT IN (SELECT <ColA> from <Table>)
 
Last edited:
INSERT INTO Test1(A)
SELECT Test1.B
FROM Test1
WHERE Test1.B
NOT IN
(SELECT Test1.A FROM Test1)
 
Top
Sign up to the MyBroadband newsletter
X