bskauge Posted October 18, 2006 Share Posted October 18, 2006 Hello,I thought this should be easy, but I just can't figure it out.I have two tables, and I want to list every record from table A where 'name' is mentioned in a list of names in table B.I've tried something like SELECT * FROM table_a WHERE name IN ('$table_b[listofnames]')andSELECT * FROM table_a WHERE name LIKE '%$table_b[listofnames]%'This works when $table_b[listofnames] only contains one name, but there is a comma separated list of names in that field. I see that $table_b[listofnames] returns the whole list, so the wildcards won't work since they are put at the beginning and at the end of the list. How do I do this? And what should I eventually do about double fornames (like "John Henry")? I really hope someone can help me out? Kindest regards,Bjorn SkaugeNorway Link to comment https://forums.phpfreaks.com/topic/24327-select-where-one-field-occurs-in-another-field-in-another-table/ Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 SELECT * FROM table_a a, table_b b WHERE a.name = b.name AND b.field1 = "x"What is the query you use to get the list from table_b? Link to comment https://forums.phpfreaks.com/topic/24327-select-where-one-field-occurs-in-another-field-in-another-table/#findComment-110651 Share on other sites More sharing options...
bskauge Posted October 18, 2006 Author Share Posted October 18, 2006 Hm, still don't get it. What is the "a" in table_a a supposed to represent? I tried this, but couldn't get it to work.Hoping for further help.regardsBjorn Skauge Link to comment https://forums.phpfreaks.com/topic/24327-select-where-one-field-occurs-in-another-field-in-another-table/#findComment-110881 Share on other sites More sharing options...
bskauge Posted October 19, 2006 Author Share Posted October 19, 2006 [quote]SELECT * FROM table_a a, table_b b WHERE a.name = b.name AND b.field1 = "x"[/quote]a.name contains just one name, b.name is a long list of names. a.name = b.name will only match if b.name contains just one name. So I want to get all the records from table a where that one name from a.name is mentioned in the b.name list. Link to comment https://forums.phpfreaks.com/topic/24327-select-where-one-field-occurs-in-another-field-in-another-table/#findComment-111098 Share on other sites More sharing options...
bskauge Posted October 19, 2006 Author Share Posted October 19, 2006 Nevermind, I found the solution:"SELECT * FROM table_a WHERE MATCH(name) AGAINST ('$table_b[listofnames]' IN BOOLEAN MODE) ORDER BY merke ASC" Link to comment https://forums.phpfreaks.com/topic/24327-select-where-one-field-occurs-in-another-field-in-another-table/#findComment-111136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.