views:

26

answers:

1

Hi there I'm new to these types of MySQL Queries. Basically, I have two tables in a MySQL Database. One is called groupmembers and the other is called users

groupmembers contains rows with two columns, a groupid and a userid

users contains rows with also two columns, a userid and a username

I am trying to write a query that searches the groupmembers table with rows with a groupid of 15, but where the userid in groupmembers links with the one in users and searches that one too.

For example:

SELECT * FROM groupmembers WHERE groupid = 15 (something to find the user row by using the userids) AND users.username = '%testquery%'

If you need any more information on this, just let me know because I am bad at explaining things! Thanks for your help.

+2  A: 

Try:

SELECT * FROM groupmembers g INNER JOIN users u ON
g.userid = u.userid WHERE g.groupid = 15 and u.username LIKE '%testquery%'
ORDER BY u.userid
Sarfraz
Thank-you so much! That works like a charm!
Jamie
@Jamie: You are welcome...
Sarfraz