Jump to content

Connect Two Tables


mcmuney

Recommended Posts

I'm currently using this code to display recent members who have signed on:
[code]$sel_mem="select * from sc_member where scm_mem_id<>'1' order by scm_lastlogin desc LIMIT 0,2";[/code]

I'd like to modify the above code to show ONLY members with images. To do this, I have to use 'sc_member_images' table, scm_mem_id would be the unique identifier on both tables. So, from results pulled from above code, show ONLY if scm_mem_id exists on table sc_member_images WHERE sci_main=1

I don't know how to incorporate the two into a single SELECT statement and I can't use sub-queries because of current mysql version. Thanks.
Link to comment
Share on other sites

If the relationship between your images and users table is 1 -> 1 then you can do an INNER JOIN on the tables and only the rows where your "scm_mem_id" values match in both tables will be returned.

Don't forget that as you are dealing with two tables in the 1 query you will have to prefix your table names

This should do it although I haven't checked it.

SELECT * from (sc_member INNER JOIN imagestable ON sc_member.scm_mem_id=imagestable.scm_mem_id) WHERE sc_member.scm_mem_id != '1' ORDER BY sc_member.scm_lastlogin desc LIMIT 0,2

....And barand beat me to it :)
he seems like a knowlegeable chap maybe he can help me with my availability calendar problem ;)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.