joining two tables with same id and same name of columns but different values

前端 未结 1 546
刺人心
刺人心 2021-01-17 01:37

I am trying to do what I just said. I have two joined tables. They are joined by same id\'s. But There are two columns with same name and I only want to output one of the co

1条回答
  •  借酒劲吻你
    2021-01-17 02:23

    Using SELECT * is generally considered harmful in production software, especially in php, for the precise reason you're asking about.

    In php, sometimes the result set is loaded into an associative array. That will cause data from all but one of each set of duplicate column names to disappear.

    You want to use

         SELECT products.id, 
                products.productname, 
                products.id AS product_id,
                bookings.*,
                etc., etc.
    

    to enumerate the columns you need in your result set. (Notice that I'm guessing at your column names).

    I know your question says you have to use SELECT *. I doubt that's true. If so it's a likely to be requirement imposed by somebody who doesn't know what they're talking about. (Stupid professor tricks come to mind.)

    If you do have to use SELECT *, you'll need to use the result set metadata to examine each column's metadata and figure out which columns you need to extract. getColumnMeta() does that.

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