Intersection table MySQL - mysql

i made three tables, two of them are just information about the customer and the product a third one is just holding the count of the products (more specific info)
two illustrate it! i put an imageSketch of tables and demanded output
Question 1: Is it a good idea doing it like i did?
Question 2: I'm working with PHP, so is it bad, when i try to populate arrays with subinformation, to build up my "demanded" table shown in the attached image?
Thank you very much

Related

How to use multiple tables for one row of one table in SQL [duplicate]

This question already has an answer here:
Mapping multiple values from the same table in mysql
(1 answer)
Closed 2 years ago.
So for the project I'm working on, I have three different tables, each holding values for individual objects. Another table is used to hold all the chosen values (not all of them!) from the three tables. I don't want a new column for every different table (as shown in the picture below), I want a row that would specify which table to use so it can use it. So basically the main table holds some of the same values from the other three tables.
I made a mock example to help explain the question. I know its kind of lame but I hope you get an idea about whats going on.
If this isn't possible using MySQL, please let me know any better suggestions. Thank you
According to the pics,those tables got nothing to indicate where to bind them.This will cause the Animal table become a totally chaos with JOIN. BUT if you just want to have a long list of all the row from specific column (which I think OP actually want) useUNION
Select Breed from Cats
UNION ALL
Select Species from Reptiles
UNION ALL
Select Type from Birds
this should get the list might be what you want.

Mysql table structure design for economic data

Dear all Mysql experts
I am very new for Mysql, please providing me some guides here. I have data as shown in picture above, and I am trying to design table structure of Mysql to store those data and the data will be added over the years, which i dont want to record same indicator multiple times. at the moment i was thinking about split the data into 3 tables: indicator table to hole indicator name, data value table to hold data value and year and the geography table to hold provinces but i am not quite sure if that approach is right please giving me some shade of light. Thank you very much.
Because its a simple question that deserves a simple answer, here is a suggestion. As per the comments, the sample data you have given is ambiguous, but with assumptions this is it.
From your data, it looks like Indicator, Category and Source are all attributes of the same entity. It also looks like there are an arbitrary number of provinces. If so then you are likely to have three tables
Indicator(IndicatorID,IndicatorText,Category,Source)
Province(ProvinceID,ProvinceName)
YearValue(IndicatorID,ProvinceID,Year,Value)
You would probably not store the national value, just add up the provinces.

Table Relationship Issues

I need some assistance linking 2 tables.
I have a products table and an additives table. Some products have 1-3 different additives in them.
I have them linked by their codes but they aren't showing as linked like my other tables. Is it because I have several different Additive Codes under 1 product?
Can someone point me in the right direction here! :D
It may help, as well as make your app more flexible, to have a intermediate table which has only the Product Code of the parent item and a field for the Additive Code. Then you link your tblProducts to the Product Code in this intermediate table, and you link the Additive Codes in the intermediate table to the tblAdditives.Product Code field. This should provide the links you are seeking, as well as allowing an unlimited Additives.
You have two options here. Table designing is a very critical stage so please carefully use the best approach as per your requirement.
Use an associative table as suggested by #Dale, this would be the best approach.
You can create a multivalued field which will allow storing more than one Additive codes in the same field. In case your additive code list is limited then you can go in this way and the advantage you have is easily displaying all values in reports.
Guide to multivalued fields

Split a table in access

I feel like this should be an easy question for someone to answer however despite my numerous searches I have not been able to find an answer (probably due to lack of dB knowledge).
The problem: I am building a research dB related to clinical examinations. I have created a main table and a couple of additional tables which have one to many relationships to the main (think, mulitple findings documented in one examination etc. I have successfully been able to create a Main form with two embedded subforms. This functions as expected.
What I would like to do is break the Main table up into a three individual tables where there are logical differences between groups of fields. This will make the dB easier to revise later on and it will make it easier to find fields.
I would like a record to be created in the two related tables every time i create a record in the first table but I cannot work out how to acheive this. When I go into the form I would like checkboxes from all three tables displayed and editable on the same page and kept in sync by the RecordID of the main table.
Any help or direction to an example dB would be greatly appreciated.
Regards,
James

Best way to store trivia alternatives?

I'm creating an application that asks the user a question and demands an answer in the form of a country.
For example: Where is the Eifell Tower located?
The user is presented with a number of alternatives, lets say 10 different countries.
The problem arrises when I want to store every answer to a mySQL-database. I have a table with all the countries, and need to store which of them were included in the question. However, doing it this way would create, in this case, 10 database rows for a single answered question. I've been looking into storing the included countries as a bit mask, but a single bit mask wouldn't be enough with over 150 possible countries.
Any help on what would be a good way to store the data is much appreciated!
Thanks!
I'd just store The relation in a table like you are suggesting. I.e, three tables where the first contains questions (Id, question_text, ..), the second table contains all the countries (Id, name, ..) and the third table contains the relation that says what country is an option in which question (question_id, country_id). Like you say this gives ten rows in the relationship table for a single question, but are you really facing a storage space or performance problem here?
If you have 10k such questions, it is still just 100k rows and less than a megabyte of data. The questions themselves will have a lot more data than that, so the relation between question and country shouldn't be an issue as far as I can see.