Solved

mysql query help

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 …

757 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

23 Experts available now in Live!

Get 1:1 Help Now