Saurabh Saxena
Saurabh Saxena

Reputation: 3215

Need help to build a sql query

I have a table with following schema

Sample table

email        |  name  |  address 
[email protected]  |  A     |  CA

I want the same set of record with five different static email addresses

Expected output

email              |   name   |   address
[email protected]  |   A      |   CA
[email protected]  |   A      |   CA
[email protected]  |   A      |   CA
[email protected]  |   A      |   CA
[email protected]  |   A      |   CA

Is this possible?

Upvotes: 0

Views: 128

Answers (1)

peterm
peterm

Reputation: 92845

Try

SELECT CONCAT('static', @n := @n + 1, '@', SUBSTRING_INDEX(email, '@', -1)) email,
       `name`,
       address
  FROM table1 CROSS JOIN  
       INFORMATION_SCHEMA.COLUMNS JOIN
       (SELECT @n := 0) n
 LIMIT 5

Output:

|             EMAIL | NAME | ADDRESS |
--------------------------------------
| [email protected] |    A |      CA |
| [email protected] |    A |      CA |
| [email protected] |    A |      CA |
| [email protected] |    A |      CA |
| [email protected] |    A |      CA |

SQLFiddle

Upvotes: 1

Related Questions