Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating "Fake" Records Within A Query

Tags:

sql

mysql

I have a very basic statement, e.g.:

SELECT pet, animal_type, number_of_legs 
FROM table

However, where table currently is, I want to insert some fake data, along the lines of:

rufus       cat     3
franklin    turtle  1
norm        dog     5

Is it possible to "generate" these fake records, associating each value with the corresponding field, from within a query so that they are returned as the result of the query?

like image 729
Thomas Avatar asked Apr 15 '15 15:04

Thomas


1 Answers

SELECT pet, animal_type, number_of_legs FROM table
union select 'rufus',    'cat',    3
union select 'franklin', 'turtle', 1
union select 'norm',     'dog',    5

This gives you the content of table plus the 3 records you want, avoiding duplicates, if duplicates are OK, then replace union with union all

edit: per your comment, for tsql, you can do:

select top 110 'franklin', 'turtle', 1
from sysobjects a, sysobjects b          -- this cross join gives n^2 records

Be sure to chose a table where n^2 is greater than the needed records or cross join again and again

like image 71
Luis Siquot Avatar answered Sep 24 '22 22:09

Luis Siquot