0

I have 2 tables:

Auth: sessionId | deviceId
Tokens: token | sessionId

(sessionId in tables auth and token are associated)

What I want to have: only one table Auth with colums sessionId, deviceId, token.

I don't know how to move column with its data from second table to first.

barbsan
  • 3,418
  • 11
  • 21
  • 28
j4f
  • 1
  • You might want to look at: https://stackoverflow.com/questions/4101739/sql-server-select-into-existing-table – computercarguy May 15 '19 at 21:39
  • You wants new column to add in the Auth table? or you want get results from both table in a single query output? also please tag proper database name. – mkRabbani May 15 '19 at 21:40
  • @mkRabbani, I need add new column to table 'Auth' and paste there data fron table 'Tokens', then I need to delete table 'Tokens' – j4f May 15 '19 at 21:47
  • @computercarguy, this is not my case. I need to insert Tokens.token to Auth.token, where Tokens.sessionId is equeal Auth.sessionId – j4f May 15 '19 at 21:55
  • Ok. With the clarification you gave, try looking at this link: https://stackoverflow.com/questions/224732/sql-update-from-one-table-to-another-based-on-a-id-match – computercarguy May 15 '19 at 21:59

1 Answers1

0

This following steps is workable for MySQL and SQL Server-

1.Add new column "Token" to the table "Auth"

ALTER TABLE Auth
ADD Token datatype -- Define the datatype

2.Update new column in Auth table using this following query-

UPDATE Auth
SET Auth.Token = Token.Token
FROM Auth
INNER JOIN Token
    ON Auth.sessionId = Token.sessionId

3.Remove the table "Token"

mkRabbani
  • 16,295
  • 2
  • 15
  • 24