0
votes

Is there a way to implement this on Google Fuision Tables Query?

...WHERE (('Field 1' =  'Value 1') OR ('Field 2' = 'Value 1'))

I am aware that OR is not implemented on Google Fusion Tables but I want to know if this query is possible. Thanks.

2

2 Answers

0
votes

For a relatively small number of conditions you can use IN, as described in the SQL reference. So in your example that would be

WHERE 'Field 1' IN ('Value 1', 'Value 2')
0
votes

There are actually a few workarounds that address the absence of the OR clause. Whether they are worth the effort I'll leave that to you the reader to judge.

One way to tackle this is to express the OR clause in terms of an AND clause. Three AND clauses to be exact, where we end up with 3 distinct fusion table queries like so:

SELECT * FROM <table_id> WHERE 'Field 1' = 'Value 1' AND 'Field 2' = 'Value 1'

SELECT * FROM <table_id> WHERE 'Field 1' = 'Value 1' AND 'Field 2' NOT EQUAL TO 'Value 1'

SELECT * FROM <table_id> WHERE 'Field 1' NOT EQUAL TO 'Value 1' AND 'Field 2' = 'Value 1'

The combined results of these three queries are effectively what the OR query would have resulted in had it been available in fusion tables.

Another approach is to perform the inverse of the OR clause (aka NOR) as follows:

SELECT ROWID FROM <table_id> WHERE 'Field 1' NOT EQUAL TO 'Value 1' AND 'Field 2' NOT EQUAL TO 'Value 1'

This query returns the ROWIDs of rows that would have been discarded by the OR clause. It follows then that if we were to take a list of all ROWIDs in a table and remove those ids generated by the NOR query, we would be left with the row ids an OR query would have produced. We can in turn use those ROWIDs to write a query to pull the full row data.