sql - Simplify UNION query that overwrites duplicate rows -


  create table section (id serial, section_name character (255) zero, version_id int tap); Create table section_version (id int primary key is not empty, version_name variable (255) zero); Enter section_version (id, version_name) value (1, 'default'), (2, 'edition a'), (3, 'version b'); ('Toys', 1), ('Animals', 1), ('car', 1), ('toys', 2), ('animal', 2), () 'instruments', 2), ( 'Toys', 3);  

I need to select Sections based on the requested section_version.version_name .

If version_name is "default" , then the query needs to be returned to all sections , where The "default" version is .

But if "Edition A" was requested, then it should return each section which "version A" and "default_" - based on section_name

Please check this Bela: < / P>

This is what I came up with:

 choose from  in the sections in sections (section_versions.id = sections.version_id) where section_versions.version_name = 'default 'And not in sections.section_name (selection of classes) Section section_ section section_versions (section_versions.id = sections.version_id) section section_version_svarion_name = 'version A') Select Union * section to section section-Versions (section_versions.id = sections.version_id) where section_versions .version_name = 'version A';  

This is probably a naive attempt, so I am looking for a better solution.

It would be nice to ask a question:

  1. Choosing "default"
  2. Selection of a specific version
  3. Working on a default version exists (device like device)

if I understand that if your intent is below the query correctly:

  Sections in section (Sections.section_id = sections.version_id) Sections_versions In the .version_name ('default', ' Version A ') section.section_name, when in case version_name' default 'then 1 and 0 end;  

For more information, see

in the "Separate section" paragraph

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -