Solved

mysql query help

Posted on 2011-09-28
4
342 Views
Last Modified: 2012-05-12
CREATE TABLE `emailaction` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `email_id` VARCHAR(150) CHARACTER SET latin1 NOT NULL DEFAULT '',
  `mail_file` TEXT,
  `subject` VARCHAR(255) DEFAULT NULL,
  `ip` VARCHAR(100) DEFAULT NULL,
  `action` INT(3) DEFAULT NULL COMMENT '0-unblock 1-block',
  `created` DATETIME DEFAULT NULL,
  PRIMARY KEY (`id`,`email_id`),
  KEY `id` (`email_id`,`action`,`id`)
) ENGINE=MYISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8


CREATE TABLE `holdemailid` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `from_emailid` VARCHAR(150) CHARACTER SET latin1 DEFAULT NULL,
  `to_emailid` VARCHAR(150) CHARACTER SET latin1 DEFAULT NULL,
  `subject` VARCHAR(255) CHARACTER SET latin1 DEFAULT NULL,
  `filename` TEXT CHARACTER SET latin1,
  `processed` INT(3) NOT NULL DEFAULT '0' COMMENT '0- unprocessed 1-processed',
  `created` DATETIME DEFAULT NULL,
  `created_1` VARCHAR(100) DEFAULT NULL,
  `action` INT(3) DEFAULT '2' COMMENT '0-unblock 1-block 2 hold',
  `modified` DATETIME DEFAULT NULL,
  PRIMARY KEY (`processed`,`id`),
  KEY `from_emailid` (`processed`,`action`,`from_emailid`,`id`),
  KEY `filename` (`action`,`processed`,`filename`(100),`from_emailid`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8

The above is the table structure in which i have to perform following operation.
check whether shadi@mangalsutrabandhan.com is present in either of the two table and the action performed on it.
if either one of them is action = 1 return BLOCK with rest db field.

The emails can be multiple it has to be scanned from from_emailid of holdemailid and email_id from emailaction table



mysql, php,linux
0
Comment
Question by:Insoftservice
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:johanntagle
ID: 36715491
select if(sum(action)>0,'BLOCK','PUT SOMETHING HERE') as message from (
select action from emailaction where emailid=' shadi@mangalsutrabandhan.com' and action=1
union
select action from holdemailid where from_emailid=' shadi@mangalsutrabandhan.com' and action=1
)

Note: untested
0
 
LVL 15

Author Comment

by:Insoftservice
ID: 36715657
i am getting error of
Every derived table must have its own alias
0
 
LVL 24

Accepted Solution

by:
johanntagle earned 500 total points
ID: 36715786
select if(sum(p.action)>0,'BLOCK','PUT SOMETHING HERE') as message from (
select action from emailaction where emailid=' shadi@mangalsutrabandhan.com' and action=1
union
select action from holdemailid where from_emailid=' shadi@mangalsutrabandhan.com' and action=1
) p
0
 
LVL 15

Author Closing Comment

by:Insoftservice
ID: 36716190
thank u very much
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now