I need to produce mailing labels for my company and I thought I would do a query for that:
I have 2 tables - tblAddress
, tblContact
.
In tblContact
I have "addressNum
" which is a foreign key of address and "labelsNum
" column that represents the number of times the address should appear in the labels sheet.
I need to create an inner join of tblcontact
and tbladdress
by addressNum
,
but if labelsNum
exists more than once it should be displayed as many times as labelsNum
is.
I suggest using a recursive query to do the correct number of iterations for each row.
Here is the code (+ link to SQL fiddle):
Wouldn't the script return multiple lines for different contacts anyway?
This yields 3 rows on my end. The labelsNum column seems redundant to me. If you add a third contact for address foo2, you would have to update all labelsNum columns for all records referencing foo2 in order to keep things consistent.
The amount of labels is already determined by the amount of different contacts.
Or am I missing something?