简体   繁体   中英

Database design: How to query multiple to multiple table

I have a system used for exhibition in Website.

The exhibition data maybe from multi-data in difference table.

Like this design: 餐桌设计

  • Table [ExhibitionType] used for differentiate category.

  • Table [ExhibitionBase] used for link extra Sub-Type table & data in different table.

My website use MySQL and PHP

Now question is I DON'T KNOW how to query it. or this design have a flaw.


EDIT 1:

I'm sorry I didn't express my intentions.

Example: I hope query a data list. first i need filter ExhibitionType like 1.

So i need create a SQL like : SELECT * FROM ExhibitionBase WHERE ExhibitionTypeId = 1

And second step i must read ExhibitionDataType and ExhibitionDataId each row data. And according to the different types of ExhibitionData data out to merge into the ExhibitionBase Sub-tables.

HOW TO DO use SQL query it.

This my question.

SELECT b.*, dt.Name, di.name
    FROM ExhibitionBase AS b
    JOIN ExhibitionDataType AS dt ON dt.id = b.ExhibitionDataType
    JOIN ExhibitionDataId   AS di ON di.id = b.ExhibitionDataId
    WHERE ExhibitionTypeId = 1

Style suggestions:

  • Do not prefix column and table names with the database name; it clutters things. ("Exhibition")
  • Do not have a column name the same as its table name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM