Solved

mysql query help

Posted on 2011-09-28
4
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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