FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL - how to group tables and query the data?





lauthiamkok
I notice Drupal has table groups in the database. I find it interesting. For instance:

Code:
block_content
     --- block_content
     --- block_content__body


How can I group a series of tables then and how to query the data?

Is it good to do so btw?
Marcuzzo
you do that by using Associative entities.

a table is referenced by a foreign key which points to the primary key of another table

Code:
TABLE: Users
PK: user_id
user_name
user_email
user_created

TABLE: Posts
PK: post_id
FK: post_userid<< points to the ID of the users table
post_timestamp
post_content
post_title




you basically query the tables by joining them.

example:
Code:
select *
FROM Posts p
JOIN Users u on u.user_id = p.post_userid



this should give you something like this:

Code:

| post_id | post_userid | post_timestamp |  post_content | post_title |  user_id | user_name | user_email | user_created |
| ------- | ----------- | -------------- | ------------- | ---------- | -------- | --------- | ---------- | ------------ |
| data comes here...
Related topics
SQL Tutorial
Critical Database Error (Or something else)
The Basics (php, mysql etc)
php or js?
sql schema primary/foreign key question
Paying f$ for content written for my site.
Installing Apache Php and MySQL [newbie tutorial]
Error connecting to mysql ; please help
How to update multiple rows in mysql with one query?
SQL problem for solving :)
MySql: More Tables and Less Fields, or the inverse???
Read only attribute cannot be removed for Folders in XP SP2
MySQL Database Backup Using PHP
Storing large integer in MySQL database
Hack to fix when MySQL crashes on Linux servers
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.