QA@IT
«回答へ戻る

1:nに対応

48
 ```sql
 SELECT
     A.id,
-    ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
-    -- NVL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
+    ISNULL((SELECT DISTINCT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
+    -- NVL((SELECT DISTINCT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
 FROM A
 ```

シンプルに~をもうちょっとシンプルにしてみた。

SELECT
    A.id,
    ISNULL((SELECT DISTINCT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
    -- NVL((SELECT DISTINCT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
FROM A
シンプルに~をもうちょっとシンプルにしてみた。

```sql
SELECT
    A.id,
    ISNULL((SELECT DISTINCT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
    -- NVL((SELECT DISTINCT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
FROM A
```

にゃー

48
 SELECT
     A.id,
     ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
-    -- ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
+    -- NVL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
 FROM A
 ```

シンプルに~をもうちょっとシンプルにしてみた。

SELECT
    A.id,
    ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
    -- NVL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
FROM A
シンプルに~をもうちょっとシンプルにしてみた。

```sql
SELECT
    A.id,
    ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
    -- NVL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
FROM A
```

・q・

48
 ```sql
 SELECT
     A.id,
-    nvl((SELECT 1 from B where B.a_id = A.id),0) AS B_exists
+    ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
+    -- ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
 FROM A
 ```

シンプルに~をもうちょっとシンプルにしてみた。

SELECT
    A.id,
    ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
    -- ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
FROM A
シンプルに~をもうちょっとシンプルにしてみた。

```sql
SELECT
    A.id,
    ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- MSSQL
    -- ISNULL((SELECT 1 from B where B.a_id = A.id),0) AS B_exists -- Oracle
FROM A
```

回答を投稿

シンプルに~をもうちょっとシンプルにしてみた。

SELECT
    A.id,
    nvl((SELECT 1 from B where B.a_id = A.id),0) AS B_exists
FROM A
シンプルに~をもうちょっとシンプルにしてみた。

```sql
SELECT
    A.id,
    nvl((SELECT 1 from B where B.a_id = A.id),0) AS B_exists
FROM A
```