getting values by joining with different id

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

getting values by joining with different id

Post by shivam0101 »

Hello,

I have two tables,

Table 1: ID, gender, name

Table 2: FILE_ID mem_Id, file_name


ID and FILE_ID (auto inc, pk)

mem_id(fk)

whenever member uploads files, a new row is inserted into Table 2

I want to get all the filenames of members whose gender does not match with the Table 2 mem_id's gender. i.e if male logs in a female files should show.




Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Code: Select all

$sql = "SELECT files.* FROM files JOIN members ON files.mem_id=members.id WHERE members.gender<>'$gender'";
(#10850)
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

Code: Select all

$gender
?

That means i should get the gender in one query and then use another query to get files? Is it possible to get it in one query itself?
Post Reply