Seder
Seder

Reputation: 2763

MySQL subqueries weird behavior

I was making a query for search but the result should be obtained from three tables and it works fine for only two characters after that it returns empty rows so can anyone help please here is my query

SELECT * 
FROM tables
WHERE table2_id
IN (

SELECT id
FROM table2
WHERE table3_id
IN (

SELECT id
FROM table3
WHERE name LIKE  '%in%'
)
OR
)
name LIKE 'in%' 
AND id <>  '8'

Any suggestions if I am making the right things and what went wrong when its more than two characters

Upvotes: 0

Views: 63

Answers (1)

Ariel
Ariel

Reputation: 26753

That's a completely ridiculous query! Use a join - that's what it's for!

SELECT tables.*
FROM tables JOIN table2 ON tables.table2_id = table2.id
     JOIN table3 ON table2.table3_id = table3.id
WHERE (name LIKE  '%in%' OR name LIKE 'in%' AND id <> 8

Upvotes: 3

Related Questions