1

ok so I do this mysql command:

SELECT CONCAT(SUBSTRING(Familenaam,1,4),SUBSTRING(Voornaam,1,4)) AS `Login` FROM tblusers

This gives me the result for johny cowbell -_> johncowb (=loginname) but this is in a query.

I want that result in my table tblusers in the column "Login". How do I do this?

Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164

2 Answers2

4

You can use INSERT INTO .. SELECT like so:

INSERT INTO tblusers(login)
SELECT 
  CONCAT(SUBSTRING(Familenaam, 1 ,4), SUBSTRING(Voornaam,1,4)) 
FROM tblusers

If you want to update, you can do this:

UPDATE tblusers t1
INNER JOIN
(
   SELECT 
     userid,
     CONCAT(SUBSTRING(Familenaam, 1 ,4), SUBSTRING(Voornaam,1,4)) login
   FROM tblusers
) t2 ON t1.userid = t2.userid
SET t1.login = t2.login
Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
1

You would do:

INSERT INTO tblusers (Login)
SELECT CONCAT(SUBSTRING(Familenaam,1,4),SUBSTRING(Voornaam,1,4)) AS `Login` FROM tblusers;

This is essentially saying "insert the result of my 'SELECT' query into the 'login' column of table 'tblusers'.

mcriecken
  • 3,217
  • 2
  • 20
  • 23