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
Solved

mysql query help

Posted on 2011-09-28
4
345 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 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