3

I have the following two YQL queries, each of which work fine on their own, but I'm pretty sure there's a way I haven't been able to find to fetch them both in a single more complicated query:

SELECT * FROM xml WHERE url="http://www.google.com/ig/api?weather=Tbilisi"
AND itemPath="//current_conditions/temp_c"

and

SELECT * FROM html WHERE url='http://amindi.ge/'
AND xpath="//*[@id='maincityholder']/h1"

The questions here with similar wording all turn out to be questions about subselects, use query.multi which doesn't seem to exist any more, or select something other than * which I couldn't get to work with either of my queries even in isolation.

It could be that the itemPath and the xpath clauses are the problem, but as I say I can't get either to work without these. Am I missing something or is this not possible with my particular queries?

hippietrail
  • 15,848
  • 18
  • 99
  • 158

1 Answers1

4

The query.multi table exists in the same place it always has. Did you forget to load that table (or the usual env=store://datatables.org/alltableswithkeys)?

There's also a yql.query.multi table, which is used in exactly the same way as query.multi but exists in YQL proper, so does not require the data table to be loaded into the environment.

The following query, taking your individual queries (and changing/escaping quotes where necessary)

SELECT * FROM yql.query.multi WHERE queries='
    SELECT * FROM xml WHERE url="http://www.google.com/ig/api?weather=Tbilisi"
    AND itemPath="//current_conditions/temp_c";
    SELECT * FROM html WHERE url="http://amindi.ge/" 
    AND xpath="//*[@id=\'maincityholder\']/h1"
';

Gives

<results>
    <results>
        <temp_c data="-2"/>
    </results>
    <results>
        <h1>6&deg;</h1>
    </results>
</results>

(Try it in the YQL console)

salathe
  • 51,324
  • 12
  • 104
  • 132
  • Hmm I haven't been able to get any examples using `query.multi` that I've found on StackExchange to work recently. I just did a search for it being deprecated in fact! It looks like it may have changed from `query.multi` to `yql.query.multi` at some point. Also the link to the YQL console doesn't work for me. – hippietrail Feb 28 '12 at 22:35
  • Great! This mostly works. I can't find a way to get the `data` attribute from the `temp_c` result though, and if I get the results in `JSON` format the first result has nothing at all. How should I modify the `itemPath` there? – hippietrail Feb 28 '12 at 22:40
  • 1
    As I said, are you loading the community tables? Click "Show Community Tables" in the console before trying to use `query.multi`. That said, there is the `yql.query.multi` table which should always be available. As for not getting things to work, without knowing what the actual problem you're seeing is… it's difficult to help you. Does the console give an error? And, I've fixed the link to try the query in the console. – salathe Feb 28 '12 at 22:41
  • 1
    The first result is there for me, in XML and JSON view. – salathe Feb 28 '12 at 22:43
  • Err no as soon as I finished testing and posted my comment, I now do see the `data` field after all. It might be nice to somehow select just it though instead of seeing it only as a child of `temp_c`... – hippietrail Feb 28 '12 at 22:45
  • It seems that "community tables" is one of the many features of YQL that I'm ignorant of. I do know many older YQL examples on SE no longer work due to some kinds of tables disappearing... Also I find the YQL documentation looks very impressing but it very hard to use in practice - it seems to go straight from too shallow to far too deep and I give up on it every time )-: – hippietrail Feb 28 '12 at 22:49
  • 1
    Somes tables do "disappear", usually when the services that YQL is querying get closed down. The more likely reason for "many" examples not working is that the table is not available in the console until you load the community tables into it. As for the documentation being impractical to use, I'm sorry but I have no involvement with those (or Y! at all) so cannot help with that particular problem. – salathe Feb 28 '12 at 22:58