0

I would like to know if it is possible to have this kind of schema:

Table 1:

Field1 | Field4 | Field3
Field1 | Field4 | Field3 
Field1 | Field4 | Field3

Table 2:

Field4 | Field5(Number of Field3)

To explain the schema, my tables have a similar field, (number4)

And my real question is:

Can I have a dynamic database where the field5 would be the count of field 3 where Table1.field4 = Table2.field4, or should I change it by hand with PHP?

Edit: "Can you provide some example data for this schema? (And perhaps some more meaningful names.)"

Table: prod Product | Description | nbOfreview Product | Description | nbOfreview

Table: Reviews Review | Description | Product

4
  • 1
    field5 is a derived attribute, is not good practice store attribute that you can derive on the fly. Commented Jul 26, 2012 at 2:08
  • Can you provide some example data for this schema? (And perhaps some more meaningful names.) Commented Jul 26, 2012 at 2:09
  • You can do that with a mysql view Commented Jul 26, 2012 at 2:14
  • You might want to ask "your real question" first, and add details afterward. My first instinct was to vote to close this as "not a real question". Commented Jul 26, 2012 at 2:20

1 Answer 1

4

You don't need an extra table.
You can use a view.

e.g:

CREATE VIEW v_data AS
SELECT field4, COUNT(field3) F_COUNT
  FROM <YOUR-TABLE>
GROUP BY  field4
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.