MySQL: How manys rows reference this row?
Posted: Fri May 30, 2003 4:11 am
First up, here's my structure
`intranet`.`page`
`intranet`.`content`
Now, my problem is, how would I get the amount of rows in `intranet`.`content` that reference a row in `intranet`.`page`, bearing in mind that a `content` row may not reference a page, which indicates it is to appear on all pages.
Preferably, it should be done in a single SQL statement, but take as many as you need.
This one has me beat
`intranet`.`page`
Code: Select all
+--------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+----------------+
| PageID | int(10) unsigned | | PRI | NULL | auto_increment |
| Title | tinytext | | | | |
+--------+------------------+------+-----+---------+----------------+Code: Select all
+-----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------+----------------+
| ContentID | int(10) unsigned | | PRI | NULL | auto_increment |
| PageID | int(10) unsigned | | | 0 | |
| Title | tinytext | | | | |
| Body | text | | | | |
| UserID | int(10) unsigned | | | 0 | |
| Order | tinyint(4) | | | 0 | |
+-----------+------------------+------+-----+---------+----------------+Preferably, it should be done in a single SQL statement, but take as many as you need.
This one has me beat