开发者

Generating duplicate responses within a MySQL SELECT query

开发者 https://www.devze.com 2023-01-14 15:28 出处:网络
I am using the report writing functionality within an application to generate barcode product labels.

I am using the report writing functionality within an application to generate barcode product labels.

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

This works fine if I want to produce one barcode label for each product returned from the database by my SELECT statement. However I want to produce 开发者_高级运维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 in which I can get a MySQL SELECT statement to return 50 identical results for each record it finds in the products table?

Thanks for any help.


I just have an ugly solution, assuming you can modify the schema: create a dummy table containing 50 records and join it in your sql queries like this: select * from products, dummyWith50Records

I'm almost shameful to write something like that, but it should work ... Hopefully someone has a better solution.


A cross join against a on-the-fly table of dud information with as many rows as you want duplicates.

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'

In this case, I'm getting 5 duplicates of every qualifying row in table.

It's not pretty, but it works, and it doesn't require creating a real table.


I am able to understand your problem... But it would be more helpful for me with an example...

I think I was doing the same thing in one of my application

0

精彩评论

暂无评论...
验证码 换一张
取 消