mysql - Have a column equal to count of another table? -


Is a column equal to counting all the rows in a separate table, where id = a column current row?

For example.

  • The table 1 has columns: id, count
  • Table 2 has column ID, table 1_id

    I have a table 1 coat I want to fill in the table 2 with the amount of rows, where table2.table1_id = table1.id

    (its parent has a relationship with the child).

    Obviously I can do it with php, I thought it would be faster than using PHP loads every time, using page loads every time. Thank you.

    Using a View and Table table1_data , you do this You can:

      Select Table 1_data as Table 1. *, Table 1_data as COUNT (*), Table 2 WHERE Table 1_data.id = table2.table1_id GROUP by table 1_data.id   

    All of this data is table1_data , a column count will be described as much as you can, and present that view as a view in which the table in most situations.

Comments