2

In QGIS 3.6.3 I'm trying to create a Virtual Layer obtained by merging 12 shapefiles (with the columns named and ordered in the same way) using the expression

SELECT *
FROM _January, _February, _March, _April, _May, _June, _July, _August, _September,
_November, _October, _December

but the software crashes.

If I wanted to create a Virtual Layer by taking data from a single column called "TEST", how can I modify the expression? I could not find the correct form.

3
  • 1
    A little more additional information, such as type of software and what tools you are using for the merge, might help provide an answer. – Kingfisher Jun 14 '19 at 12:47
  • thanks @kazuhito, I tried the formula (2) and it works. I asked why when I tried it I couldn't get it to work (because I was wrong to write the command to join all the layers) thanks again for help – Fabrizio Jun 21 '19 at 11:23
  • Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful. - From Review – TomazicM Jun 21 '19 at 11:42
2

Like this? (not tested).

(1) Merging all fields of 12 layers

SELECT * FROM "_January"
UNION ALL
SELECT * FROM "_February"
UNION ALL
............. // please repeat - March to November
UNION ALL
SELECT * FROM "_December"

(2) Merging layers, and selecting only TEST field

SELECT TEST, "_January".geometry FROM "_January"
UNION ALL
SELECT TEST, "_February".geometry FROM "_February"
UNION ALL
............ // please repeat  - March to November
UNION ALL
SELECT TEST, "_December.geometry" FROM "_December"

UPDATE (3) Using table from (2), choose only TEST field is TRUE

SELECT a.TEST, a.geometry AS geometry
FROM (
     SELECT TEST, "_January".geometry FROM "_January"
     UNION ALL
     SELECT TEST, "_February".geometry FROM "_February"
     UNION ALL
     ............ // please repeat  - March to November
     UNION ALL
     SELECT TEST, "_December".geometry FROM "_December"
) AS a
WHERE TEST = 'TRUE'
3
  • work, thanks! I take advantage of it, instead I wanted to select from the TEST column the TRUE values, how can I modify the sql formula? – Fabrizio Jun 14 '19 at 13:31
  • hi @Fabrizio How about add another filter on top of the expression written in the above example (2)? I mean we can put the output of (2) as a table, and set SELECT syntax from this new table. – Kazuhito Jun 14 '19 at 13:38
  • hi again @Fabrizio Not sure if it works, but I tried to add (3) which selects only if TEST field is TRUE. Let me know if I have misunderstood the request. – Kazuhito Jun 14 '19 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.