Mysql query is not working but i could not guess why

Somesh Gaur

Hello Friends I have two tables one is customer and the other one is new_party_estimate. But My following query is not working. Please help me to solve this problem.

SELECT 
  acc_name,
  customer_id 
FROM
  customers 
WHERE STATUS = 'e' 
AND acc_name NOT IN (
  SELECT DISTINCT 
    customer 
  FROM
    new_party_estimate 
  WHERE closed = '0' 
  AND (
    customer_alt = '' 
    OR customer_alt IS NULL
  )
) 
ORDER BY acc_name 

I am running the sub query separately and it is giving the output. But When i run the full query at once the mysql shows empty result. Please tell what would be the problem!

Table Customers is Following with few records.

acc_name                      customer_id
CAMPUS FASHION_khyati         CAM-11
PAPPU SUIT HOUSE              PAPAAR5
R K FASHION                   R KAAR6
SELECTION MENS WEAR           SELAAR7

Table new_party_estimate is Following with few records.

    customer
    LOVELY DRESSES
    ASHIRWAD GARMENTS
    AKASH DEEP
    ABDUL LATIF READYMADE SALE
Kickstart

Nothing obvious in you query, although IN can be inefficient (using EXISTS would be more efficient).

Another alternative would be to do a LEFT JOIN but only bring back records where there is no match:-

SELECT acc_name,
        customer_id 
FROM customers 
LEFT OUTER JOIN new_party_estimate
ON customers.acc_name = new_party_estimate.customer
AND closed = '0' 
AND (customer_alt = '' 
OR customer_alt IS NULL)
WHERE new_party_estimate.customer IS NULL
AND STATUS = 'e' 
ORDER BY acc_name 

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

MySQL query in PHP is not working

分類Dev

mysql insert into query not working

分類Dev

Why I could not assign a wordpress function to a variable?

分類Dev

Why Is MySQL Bridge Table Not Working?

分類Dev

Why wont this MySQL Query save

分類Dev

Why is my SQL "INSERT INTO" query not working?

分類Dev

Why am I getting Unknown column in 'where clause' using a sub-query alias with MySQL?

分類Dev

Query working in mysql but not from c# code

分類Dev

Mysql join query help, not working as required

分類Dev

mysql query compare dates, DATEDIFF not working

分類Dev

Mysql select query working but giving error on update query

分類Dev

Why is my MySql Server connection string not working?

分類Dev

Char automatically converts to int (I guess)

分類Dev

Why do I get this error? The provider could not determine the Double value

分類Dev

Why must I use + in mongoDB query

分類Dev

Can someone explain why this query isn't working?

分類Dev

Why same postgres query is not working for double digit number?

分類Dev

Not getting expected results with the query I've in MySQL

分類Dev

How can I optimize this mysql query please?

分類Dev

Could someone explain why my Adjacent Selector isn't working as expected in jQuery?

分類Dev

Comparing mysql password hashes using query row returning 0 (not working)

分類Dev

MobX - Why should I use `observer` when I could use `inject` when injecting data into a React component

分類Dev

Why I obtain these error messages when I try to install gem bundler on Ubuntu? (Could not create Makefile)

分類Dev

How could I center a div that is inside a div? Auto margins aren't working

分類Dev

cmake not working, could not exec qmake

分類Dev

dplyr code was working, now isn't, and I'm not sure why

分類Dev

Why isn't gatsby-transformer-remark adding IDs to headings so that I could link to them?

分類Dev

Why I can't make any kind of join in this query?

分類Dev

Does anyone know why I am not getting any results with this query?

Related 関連記事

  1. 1

    MySQL query in PHP is not working

  2. 2

    mysql insert into query not working

  3. 3

    Why I could not assign a wordpress function to a variable?

  4. 4

    Why Is MySQL Bridge Table Not Working?

  5. 5

    Why wont this MySQL Query save

  6. 6

    Why is my SQL "INSERT INTO" query not working?

  7. 7

    Why am I getting Unknown column in 'where clause' using a sub-query alias with MySQL?

  8. 8

    Query working in mysql but not from c# code

  9. 9

    Mysql join query help, not working as required

  10. 10

    mysql query compare dates, DATEDIFF not working

  11. 11

    Mysql select query working but giving error on update query

  12. 12

    Why is my MySql Server connection string not working?

  13. 13

    Char automatically converts to int (I guess)

  14. 14

    Why do I get this error? The provider could not determine the Double value

  15. 15

    Why must I use + in mongoDB query

  16. 16

    Can someone explain why this query isn't working?

  17. 17

    Why same postgres query is not working for double digit number?

  18. 18

    Not getting expected results with the query I've in MySQL

  19. 19

    How can I optimize this mysql query please?

  20. 20

    Could someone explain why my Adjacent Selector isn't working as expected in jQuery?

  21. 21

    Comparing mysql password hashes using query row returning 0 (not working)

  22. 22

    MobX - Why should I use `observer` when I could use `inject` when injecting data into a React component

  23. 23

    Why I obtain these error messages when I try to install gem bundler on Ubuntu? (Could not create Makefile)

  24. 24

    How could I center a div that is inside a div? Auto margins aren't working

  25. 25

    cmake not working, could not exec qmake

  26. 26

    dplyr code was working, now isn't, and I'm not sure why

  27. 27

    Why isn't gatsby-transformer-remark adding IDs to headings so that I could link to them?

  28. 28

    Why I can't make any kind of join in this query?

  29. 29

    Does anyone know why I am not getting any results with this query?

ホットタグ

アーカイブ