Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6591389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:25:02+00:00 2026-05-25T17:25:02+00:00

I have a MySQL table with the following schema: +————–+————-+——+—–+———+—————-+ | Field | Type

  • 0

I have a MySQL table with the following schema:

+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| id           | int(11)     | NO   | PRI | NULL    | auto_increment |
| country_dest | int(11)     | YES  |     | NULL    |                |
| type         | varchar(56) | YES  |     | NULL    |                |
| version      | varchar(56) | YES  |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+

For every country_dest there will be several type – business, tourist, etc (but each country_dest may have different or totally unique types).

I want to make sure that for every type, in every country there is a particular value of version (the same value eg ‘complete’).

So for instance:

+----+--------------+------------+----------+
| id | country_dest | type       | versions |
+----+--------------+------------+----------+
|  1 |            8 | business   | single   |
|  2 |            8 | business   | complete |
|  3 |            8 | tourist    | single   |
|  4 |            8 | tourist    | complete |
|  5 |            8 | diplomatic | single   |
|  6 |           14 | business   | single   |
|  7 |           14 | business   | complete |
|  8 |           14 | private    | single   |
|  9 |           31 | business   | double   |
| 10 |           31 | business   | complete |
+----+--------------+------------+----------+

If that was the table contents, then the query would return that:

country_dest: 8 with type: diplomatic, and
country_dest: 14 with type: private

don’t have the complete value.

Output should be:

+---------------+---------------+
| country_dest  |      type     |
+---------------+---------------+
|             8 |   diplomatic  |
|            14 |   private     |
+---------------+---------------+

It seems like it would be great to loop through this in a for loop, but that’s not how it’s done. I’ve tried lots of solutions but I can’t get them to work and I’m sure there must be a tried and tested way of doing this. This is my latest effort:

SELECT form_dest, form_vtype, form_ispack FROM _forms f
WHERE form_dest IN 
    (SELECT DISTINCT dest.form_dest FROM _forms) dest
AND form_vtype IN 
    (SELECT DISTINCT form_vtype FROM _forms as type)
AND NOT EXISTS  
    (SELECT * FROM _forms 
    WHERE f.form_dest = dest.form_dest 
    AND f.form_type = type.form_type 
    AND f.form_ispack = "Yes") 

but I get errors.

Grateful for any help on this. Cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:25:03+00:00Added an answer on May 25, 2026 at 5:25 pm

    Using a NOT EXISTS should be enough to get the results you require.

    To get the entire _forms record, you can wrap the statement into a subselect and join it again with _forms.

    SQL Statement

    SELECT  country_dest
            , type
    FROM    _forms invalid
    WHERE   NOT EXISTS (        
              SELECT  country_dest
                      , type
              FROM    _forms valid
              WHERE   versions = 'complete'
                      AND valid.country_dest = invalid.country_dest
                      AND valid.type = invalid.type
            )          
    GROUP BY
            country_dest
            , type
    

    or equivalent using a DISTINCT

    SELECT  DISTINCT country_dest
            , type
    FROM    _forms invalid
    WHERE   NOT EXISTS (        
              SELECT  country_dest
                      , type
              FROM    _forms valid
              WHERE   versions = 'complete'
                      AND valid.country_dest = invalid.country_dest
                      AND valid.type = invalid.type
            )          
    

    Test script (SQL Server)

    ;WITH _forms (country_dest, type, versions) AS (
      SELECT  8, 'business', 'single'
      UNION ALL SELECT  8, 'business', 'complete'
      UNION ALL SELECT  8, 'tourist', 'single'
      UNION ALL SELECT  8, 'tourist', 'complete'
      UNION ALL SELECT  8, 'diplomatic', 'single'
      UNION ALL SELECT 14, 'business', 'single'
      UNION ALL SELECT 14, 'business', 'complete'
      UNION ALL SELECT 14, 'private', 'single'
      UNION ALL SELECT 31, 'business', 'double'
      UNION ALL SELECT 31, 'business', 'complete'
    )
    SELECT  country_dest
            , type
    FROM    _forms f
    WHERE   NOT EXISTS (        
              SELECT  country_dest
                      , type
              FROM    _forms f2
              WHERE   versions = 'complete'
                      AND f2.country_dest = f.country_dest
                      AND f2.type = f.type
            )          
    GROUP BY
            country_dest
            , type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with the following schema: +------------------+ |Field | Type | +------------------+
I have the following MySQL table structure: num field company phone website 1 Gas
I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
I have a MySQL table with the following schema: +---------+---------+----------------------+------------+ | User ID |
I have a table with the following schema in MySql 5.1: Venue (id, name,
I have the following mysql table schema: SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -- -- Database: `network` --
I have a MySQL table with the following data (simplified): INSERT INTO `stores` (`storeId`,
I have the following table: mysql> SELECT * FROM `bright_promotion_earnings`; +----+----------+------------+----------+-------+ | id |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.