Reputation: 741
I have a form in which I fill following things:
Nick: SbsNick;
Item: SomeItem1; Price: PriceOfItem1
Item: SomeItem2; Price: PriceOfItem2
Item: SomeItem3; Price: PriceOfItem3
................................
And I can add items with varying number of inputs. It means that each Nick can have different number of items.
I want to create the database where I can query
SELECT ? FROM items WHERE Item="SomeItem"
and receive all nicks and prices of SomeItem, i.e. I want to end up with the table like that:
Nick |Price
-------------
Jack |20
BlackB |18
Karl |25
.............
I have a problem with designing such database, cause I feel that I lack of one additional dimension. If I want to fix ammount of tables I see that I need unlimited amount of columns in some table. If I want to bound ammount of tables and columns I see that cells must behave like array.
Is there a clever way to design such database?
Upvotes: 0
Views: 53
Reputation: 2468
I think that you need to study about Relational Data Bases. I can not understand what is your exact problem.
You need three tables:
USERS, ITEMS, PURCHASES
. One for representing the users, another for the items and the last for representing the relation between both of them.
USERS(ID_USER, NAME, NICK, REGISTER_DATE)
ITEMS(ID_ITEM, DESCRIPTION, PRICE)
PURCHASES(ID_PURCHASE, ID_USER, ID_ITEM, PRICE, PURCHASE_DATE)
I have used the name PURCHASES because I personally don't know the exact nature of the relation between users and items in your problem, be free to name that third table whatever you want.
There is no need for extra new columns for each purchase that the user does in table USERS nor in table ITEMS, you only have to insert a new row in table PURCHASES.
Upvotes: 1