从具有相同列的不同表中获取值到数组中

时间:2021-02-06 15:39:29

My SQL-request looks like this

我的SQL请求看起来像这样

SELECT Objects.name, Elements.name, Labels.name....

I write values from this request into an array, like this:

我将此请求中的值写入数组,如下所示:

while([results next]){

[arrayObjects addObject:[results stringForColumn:@"Objects.name"]];
    [arrayElements addObject:[results stringForColumn:@"Elements.name"]];
    [arrayLabels addObject:[results stringForColumn:@"Labels.name"]];
      ...

}

I see this message: "Warning: I could not find the column named 'objects.name'"

我看到这条消息:“警告:我找不到名为'objects.name'的列

But if I write

但是如果我写的话

while([results next]){

[arrayObjects addObject:[results stringForColumn:@"name"]];
    [arrayElements addObject:[results stringForColumn:@"name"]];
    [arrayLabels addObject:[results stringForColumn:@"name"]];
      ...

}

then I have only the last value for all arrays.

然后我只有所有数组的最后一个值。

Is there a way to fix this?

有没有办法来解决这个问题?

1 个解决方案

#1


1  

Here's something to try, I'm not sure if this is what you are looking for:

这是尝试的东西,我不确定这是否是您正在寻找的:

Instead of each column using the "same name" like this: "SELECT Objects.name, Elements.name, Labels.name...."

而不是每列使用“相同的名称”,如下所示:“SELECT Objects.name,Elements.name,Labels.name ....”

Try this: "SELECT Objects.name as O_name, Elements.name as E_name, Labels.name as L_Name ...."

试试这个:“SELECT Objects.name as O_name,Elements.name as E_name,Labels.name as L_Name ....”

then, you can use the unique column names:

然后,您可以使用唯一的列名称:

[arrayObjects addObject:[results stringForColumn:@"O_name"]];
[arrayElements addObject:[results stringForColumn:@"E_name"]];
[arrayLabels addObject:[results stringForColumn:@"L_name"]];
  ...

#1


1  

Here's something to try, I'm not sure if this is what you are looking for:

这是尝试的东西,我不确定这是否是您正在寻找的:

Instead of each column using the "same name" like this: "SELECT Objects.name, Elements.name, Labels.name...."

而不是每列使用“相同的名称”,如下所示:“SELECT Objects.name,Elements.name,Labels.name ....”

Try this: "SELECT Objects.name as O_name, Elements.name as E_name, Labels.name as L_Name ...."

试试这个:“SELECT Objects.name as O_name,Elements.name as E_name,Labels.name as L_Name ....”

then, you can use the unique column names:

然后,您可以使用唯一的列名称:

[arrayObjects addObject:[results stringForColumn:@"O_name"]];
[arrayElements addObject:[results stringForColumn:@"E_name"]];
[arrayLabels addObject:[results stringForColumn:@"L_name"]];
  ...