?
Solved

mysql query help

Posted on 2011-09-28
4
Medium Priority
?
348 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 2000 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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