-2

我在 SQLite 数据库中有 3 个表,它们之间没有任何关系。

我必须返回关于 3 个表之一的所有字段,其中我有这样的条件:

(table1.field1="something" and table1.field2="something") OR (table2.filed1="something" and table2.field2="something") ...

所以我想知道哪个表有“某物”的字段,并用该信息返回该表的其他字段。

如果问题根本不清楚,我会尝试用问题做一张图片。

编辑:

我试过这样的事情:

SELECT idpontosturisticos,idrestauracao,idalojamento from Alojamento,pontosturisticos ,restauracao WHERE (alojamento.latitude=41.158764 AND alojamento.longitude=-7.784906 AND alojamento.nome='Restaurante1') OR (pontosturisticos.latitude=41.158764 AND pontosturisticos.longitude=-7.784906 AND pontosturisticos.nome='Restaurante1') OR (restauracao.latitude=41.158764 AND restauracao.longitude=-7.784906 AND restauracao.nome='Restaurante1')
4

1 回答 1

1

I think you just want a UNION.

Like this:

SELECT idpontasturisticos, otherfielda1, otherfielda2, otherfieda3 from pontosturisticos WHERE (latitude=41.158764 AND longitude=-7.784906 AND nome='Restaurante1') 
UNION 
SELECT idrestauracao, otherfieldb1, otherfieldb2, otherfiedb3 from restauracao WHERE (latitude=41.158764 AND longitude=-7.784906 AND nome='Restaurante1') 
UNION
SELECT idalojamento, otherfieldc1, otherfieldc2, otherfiedc3 from alojamento WHERE (latitude=41.158764 AND longitude=-7.784906 AND nome='Restaurante1') 

You just need to make sure that you retrieve the same number of fields from each of the three subqueries. The fields don't have to be the same name, but they will all come down in the same column. The column names will be the names from the first subquery (in this case, idpontasturistocs, otherfieda1, otherfielda2, otherfielda3)

于 2013-06-13T05:21:45.983 回答