[thelist] Sql join problem

Les Lytollis leslytollis at dimensions-corporatewear.co.uk
Fri Dec 10 03:28:34 CST 2004

Bit rusty on mySQL sysntax, but generally you only need to SELECT one
side of the field in the join condition, define the JOIN type and
specify a JOIN CONDITION.  

SELECT members.member_id 
FROM members 
INNER JOIN profile 
ON profile.member_id = members.member_id

WHERE profile.category_id = '1'
AND profile.content = 'blah' 
AND (members.username LIKE '%party%'
	OR members.email_address LIKE '%party%') 
LIMIT 0, 12

I am a little confused by your requirement though, you say you want the
statement to select the member_id from *either* the profile or members
table - does this mean that you don't want only those that match in both

If you want to "merge" the results from two dfferent tables. Look at

>Not sure what i'm doing wrong with my join in mysql.
>so that statement should select the 'member_id' from either 
>the profile or members tables where the username or 
>email_address columns are LIKE %party% and where the 
>'category_id' and 'content' match up. limit of 12 for display.

********************Confidentiality Notice & Disclaimer ***********************
This message, together with any attachments, is for the confidential and exclusive use of the addressee(s).
If you receive it in error, please delete the message and its attachments from your system immediately and notify us by return e-mail.
Do not disclose, copy, circulate or use any information contained in this e-mail.

(1) Whilst we have taken reasonable precautions to ensure that any attachment to this e-mail has been swept for viruses, we cannot accept liability for any damage sustained as a result of software viruses and would advise that you carry out your own virus checks before opening any attachment.
(2) The sender shall remain solely accountable for any statements, representations or opinions that are clearly his or her own and not made in the course of employment.

More information about the thelist mailing list