Reputation: 9890
i have two tables
tweets(id,user_id,lang);
//lang is enum (en,fr,ar,ch)
user(id,accepted_lang);
// accepted_lang is varchar and can vary like en,ar OR ar,fa OR en,fa etc
I want to select all tweets with accepted languages by user.
select * from tweets where lang in (select accepted_lang from user where id=16);
#return 0 row
If i replace select accepted_lang from user where id=16
with its result fa,ar
it will return some of rows
select * from tweets where lang in ('fa','ar');
#return some of rows
So actually my problem is how to convert varchar to enum or table
Upvotes: 0
Views: 6863
Reputation: 5041
Probably because you haven't mentioned the second table and got user_lang instead of accepted_lang in your query
select * from tweets, user where tweet_lang = accepted_lang and user.id=5
However you probably want to accept all tweets from a specific user
select * from tweets
left join user on tweets.user_id = user.id
where -- your conditions here
Upvotes: 1
Reputation: 15603
Your query should be this:
SELECT * FROM tweets, user
WHERE tweets.tweet_lang = user.accepted_lang
AND user.id=5
As there is no column named user_lang
probably this is accepted_lang
Upvotes: 0