Generating duplicate responses in a MySQL SELECT query

I use the reporting features in the application to create barcode product shortcuts.

The reporting system allows me to use the MySQL SELECT statement to get the information I need from our database and present it in a Jasper Reports JSXML file that formats the report.

This works fine if I want to create one barcode label for each product returned from the database using the SELECT statement. However, I want to create fifty copies of each product label.

Easy enough if I had access to the code, but all I can change is the SQL statement.

Can anyone suggest a way I can get the MySQL SELECT statement to return 50 identical results for every record that it finds in the product table?

Thanks for any help.

+3
source share
3 answers

I just have an ugly solution, assuming you can change the schema: create a dummy table containing 50 records and attach it to your sql queries as follows: select * from the products, dummyWith50Records

I am almost ashamed to write something like this, but it should work ... I hope someone has a better solution.

+1
source

" " , .

SELECT t.* 
FROM table t 
JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) dud 
WHERE t.field = 'condition'

5 table.

, , .

+1

I can understand your problem ... But I would be more helpful with an example ...

I think I did the same in one of my applications

0
source

Source: https://habr.com/ru/post/1763170/


All Articles