I have the following query:
SELECT col1, col2, col3 FROM tb1
WHERE col4=ANY(
SELECT col1 FROM tb2
WHERE col2=(SELECT col1 FROM tb3 WHERE col3='php generated string')
AND col3=(SELECT col2 FROM tb3 WHERE col3='same string as above')
);
It works, but it’s very slow. I know there is a much better (and faster) way to do this, but my lack of experience with SQL queries means I’m trying to make this harder than it needs to be. I’ve tried using a JOIN, but I don’t truly understand how to make that work in this case either.
Any help is much appreciated.
You’re right that you need to learn how to use
JOIN. If you ever are matching up values from one column across multiple tables, you should probably beJOINing the tables togetherONthat column.