mySQL simple left join statement

Dear Experts,
below mysql statement is working but I think I do something wrong,
it takes too long to bring the data.

What is wrong with it? How should I improve it?
 I use MySQL

SELECT table1.uid,table1.isim, table2.toplam, table2.bayikodu
FROM table1
LEFT JOIN table2 ON table2.bayikodu = table1.uid	
Where bayikodu is Null

Open in new window

LVL 1
BRMarketingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leonidas DosasCommented:
Take a look this article about server memory buffet. sql cache buffer.
I think that there you must focus.
0
johnsoneSenior Oracle DBACommented:
Assuming TABLE2.BAYIKODU is indexed, try this:
SELECT table1.uid, 
       table1.isim, 
       NULL, 
       NULL 
FROM   table1 
WHERE  NOT EXISTS (SELECT 1 
                   FROM   table2 
                   WHERE  bayikodu = table1.uid); 

Open in new window

Functionally equivalent.  Your original is doing an outer join, but looking for rows where the join failed (the IS NULL condition in the WHERE clause).

Rather than join the tables together and looking for the missing join condition, just do the check in the second table.  Have to scan TABLE1 either way, so you will not get a benefit there.  Just doing a keyed lookup in an index on TABLE2 should be faster than pulling the row back and trying to fully join the tables.
2
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Also consider running an EXPLAIN on your query.

You'd be surprised how much you can learn from a simple EXPLAIN, for example, you may learn (see jonsone's comment) that adding a simple index in one place may make a huge difference in how fast your query runs, as your data size increases.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

BRMarketingAuthor Commented:
Dear David, how can I run Explain on my query?
Thank you, it's a good advise
0
BRMarketingAuthor Commented:
Dera All,
Where can i learn all this mySql joint statement logics?
I think, i need to learn the logic behind
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Just insert the word EXPLAIN just before your SELECT.

As for learning SQL, start with YouTube + then move onto Udemy + other courseware providers.

There are so many great courses.

A really great starting point are the several books written on High Performance MariaDB, you can find at Amazon. All this information is available for free + these books do a great job of collecting + organizing this info. Likely these books will save you many hours of time.

Welcome to SQL-ing!
2
BRMarketingAuthor Commented:
THANK YOU All
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.