1

I would like to check streets using a table.

  1. the query is not optimal
  2. the query takes much too long

Can someone help me

SELECT id, strasse, plz
FROM `adress`
WHERE strasse NOT IN (
    SELECT street
    FROM post_plz
    WHERE `street` like adress.strasse AND plz like adress.plz
)
LIMIT 5; 

2 Answers 2

1

You could try using aleft join between the table and check for not mactching values

SELECT id, strasse, plz 

from `adress` 
left join  post_plz on strasse = street
  AND `street` like adress.strasse 
    AND plz like adress.plz
WHERE street is null
 LIMIT 5;
Sign up to request clarification or add additional context in comments.

1 Comment

This query works just as well or just as poorly. Apparently the zip codes are not checked properly!? However, the runtime had not improved (about 80 seconds) Only when I declared the column street as index, the script ran within 0.4 seconds. It does not run perfectly, but for my purposes it is enough. Thanxx
0
SELECT id, strasse, plz
FROM adress
WHERE NOT EXISTS ( SELECT NULL
                   FROM post_plz
                   WHERE post_plz.street = adress.strasse 
                     AND post_plz.plz = adress.plz )
-- ORDER BY {expression}  
LIMIT 5

Without ORDER BY the query returns non-deterministic output (two query executions may produce different outputs). So it is strongly recommended to add some rows ordering.

The indices post_plz (adress, plz) and adress (strasse, plz, id) must improve.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.