Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
MYSQL query two tables (JOIN) . is there a way to match only 1 entry ( 2nd table might have multiple matches)?
i have two table which I can either INNER JOIN or LEFT JOIN ( or whatever you would suggest).
I need to match a query with the first table but only when there is at least one in the second table:
example: search members who have at least one email entered
there is a member table and an email table where each member can enter many email addresses
the solution i have for now is very clumsy: I have a column in the member table that has the count of emails the member has....but I am hoping for a more elegant way to do this
thank you
3 Answers
- 1 decade agoFavorite Answer
If you want to display a record only when there is at least one matching record in the second table then you can use INNER JOIN.
If you want to return only one record even if there are multiple records in the second table then you may want to use a subquery, for example:
SELECT userid, firstname, lastname
FROM TABLE1
WHERE id in (Select userid FROM TABLE2)
Source(s): I am a web applications developer - Anonymous5 years ago
SELECT [column fields that you want to retrieve] FROM table1 INNER JOIN table2 ON table1.primarykey = table2.foreignkey INNER JOIN table3 ON table2.primarykey = table3.foreignkey INNER JOIN table4 ON table3.primarykey = table4.foreignkey INNER JOIN table5 ON table4.primarykey = table5.foreignkey WHERE field = yourcriteria you can continue on. primary key is the first table's key and foreign key is the reference field if you want to get records with no matching records from other table you use an OUTER JOIN LEFT OUTER JOIN table6 ON table5.primarykey = table6.foreignkey you get the idea. ;)
- Anonymous1 decade ago
$query = "SELECT * FROM table1, table2 WHERE table1.email = table2.email AND table2.email = 'example@email.com'"
that query should be able to find the email address in table2 and get the information from table1 that matches it.
that what your after?
use mysql_num_rows($query) to get the number of rows.