且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

连接具有相同ID和相同列名但值不同的两个表

更新时间:2022-11-17 15:11:14

使用SELECT *通常认为出于您要询问的确切原因,在生产软件(尤其是php)中有害.

在php中,有时将结果集加载到关联数组中.这将导致除每组重复的列名称中的一组以外的所有数据消失.

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.

您要使用

     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).

我知道您的问题说您必须使用SELECT *.我怀疑那是真的.如果是这样,那可能是一个不知道他们在说什么的人强加的要求. (愚蠢的教授把戏浮现在脑海.)

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.)

如果必须使用SELECT *,则需要使用结果集元数据来检查每一列的元数据,并找出需要提取的列. getColumnMeta() 可以做到这一点.

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.