Search Multiple Tables at in one query (MySQL/PHP#)

后端 未结 2 900
温柔的废话
温柔的废话 2021-01-29 03:25

I have about 15 tables, each table containing about 10, 000 rows and about 30 columns. I want the users of my site to be able to search for a Part Number, or a product/descripti

相关标签:
2条回答
  • 2021-01-29 03:40

    If all the tables have the same structure you might be able to do that. (That sounds like it's a simplistic manual partitioning scheme.)

    Anway to join multiple tables you can use

    SELECT * FROM tbl1
    UNION ALL
    SELECT * FROM tbl2
    ...
    

    And to get your simple access method you might create a view on that concatenation:

    CREATE VIEW alltables AS
        SELECT * ... UNION ... 
    

    Not ever tested this. But this view would then facilitate SELECT * FROM alltables WHERE find($q)... - you'd still need a valid query for the columns of course.

    0 讨论(0)
  • 2021-01-29 03:48

    why do u have so many tables? why not have only one table of part #'s, than another table of descriptions and join on the part number?

    0 讨论(0)
提交回复
热议问题