I had a hard time coming up with a title, so I hope this is somewhat understandable…
I have the following table:
items: id|name|...|visibleItems
E.g. it contains:
1|test1|...|2
2|test2|...|1
3|test3|...|2
This is then joined with another table (customers) and I would like to list it as follows:
cust1|test1|...
cust2|test1|...
cust3|test2|...
cust4|test3|...
cust4|test3|...
…thus using the ‘visibleItems’ as the number for items listed.
The SQL I have is something simple like:
SELECT [values] FROM [tables] WHERE [statements] ORDER BY name
Does this make sense? If so, what to do? 🙂
Do you have a customer_id foreign key in the items table? If so, you could do something like this:
visibleItemswouldn’t control how many customers are listed per item–the foreign key relationship and join would do that.See here for a decent explanation of the various join types: A Visual Explanation of SQL Joins.