Hi Everyone

I have the following problem

I have members table, whoisonline table and memberimages table.

Here are the tables:

PHP Code:

CREATE TABLE 
IF NOT EXISTS `members` (
  `
memberidint(11NOT NULL AUTO_INCREMENT,
  `
ethnicoriginidint(11) DEFAULT NULL,
  `
nationalityidint(11) DEFAULT NULL,
  `
residencecountryidint(11) DEFAULT NULL,
  `
cityidint(11) DEFAULT NULL,
  `
subscriptiontypeidint(11) DEFAULT NULL,
  `
relationshipstatusidint(11) DEFAULT NULL,
  `
educationlevelidint(11) DEFAULT NULL,
  `
emailvarchar(255NOT NULL,
  `
usernamevarchar(255NOT NULL,
  `
passwordvarchar(255NOT NULL
  
`sexvarchar(255NOT NULL
  
  
  CREATE TABLE 
IF NOT EXISTS `whoisonline` (
  `
recordidint(11NOT NULL AUTO_INCREMENT,
  `
memberidint(11NOT NULL,
  `
lastlogintimestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `
loggedfromipvarchar(255NOT NULL
  
  
  CREATE TABLE 
IF NOT EXISTS `membersimages` (
  `
imageidint(11NOT NULL AUTO_INCREMENT,
  `
memberidint(11NOT NULL,
  `
filenamevarchar(255NOT NULL,
  `
dateuploadeddatetime NOT NULL,
  `
uploadedfromipvarchar(255) DEFAULT NULL,
  `
sorderint(11) DEFAULT NULL,
  `
visibletinyint(4) DEFAULT NULL 
I would like to get all members where sex is 2 which have images in membersimages and are online now.

I manage to do the first, that is to get all members which sex = 2 and have images in membersimages table with this query

PHP Code:

select 
from members where sex '2' AND exists (select memberid from membersimages where members.memberid membersimages.memberid
but I have problem to get ONLY the users which are online. I try with someting like this:

PHP Code:

AND exists (SELECT FROM whoisonline WHERE TIMESTAMPDIFF(MINUTElastloginCURRENT_TIMESTAMP) <= 30
but without any success.

Can anyone help me with this?

I always have problems with those kind of queries...Any book recommendation that will help me to learn those kind of queries will be deeply appreciated.

Regards, Zoreli