Reputation: 23
I'm trying to get data from multiple tables with a search keyword.
Here are my tables:
Table -1 translator
id | Name | English | User_id|
1 | کے | ky | 0 |
Table-2 boy
id | Name | English | meaning |
1 | علی | Ali | بلند |
Table-3 girls
id | Name | English | meaning|
1 | سحرش | Sahrish | جادو |
I want to get the English value with search keyword of 'علی'
from both tables.
How do I relate 3 tables with 2 columns where the column name is equal?
I want to get something like this:
id | Name | English |
1 | علی | Ali |
I'm trying this query:
SELECT translator.Name,translator.English,boy.Name,boy.English,girls.Name,girls.English
FROM translator
INNER JOIN
(boy INNER JOIN girls
ON girls.Name = boy.Name)
ON translator.Name = boy.Name
WHERE translator.Name = 'علی' LIMIT 1
Upvotes: 2
Views: 269
Reputation: 133370
Looking to your result seems you need a UNION (and not a JOIN)
select * from (
SELECT Name, English
FROM translator
UNION
SELECT Name, English
FROM boy
UNION
SELECT Name, English
FROM girls
) t
where name = 'yourvalue'
Upvotes: 1