473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

custom sql statment required

136 100+
Hi,

I require help to design a sql statement to get some specific dataset. This sql statement I need to run using php script.
Let me first describe the table structure. Table 'tblservicedetails' contains the following fields:
Expand|Select|Wrap|Line Numbers
  1. 'srv_id' INT(11)  NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  2. 'srv_mcid' INT(6) NOT NULL ,
  3. 'srv_jobcodeid' INT(2) NOT NULL ,
  4. 'srv_date' INT(11) NOT NULL DEFAULT 0 
  5. ......
Now when I run the following sql statement :
Expand|Select|Wrap|Line Numbers
  1. SELECT srv_id, srv_mcid, srv_jobcodeid, srv_date
  2. FROM tblservicedetails
  3. WHERE srv_mcid IN (264, 460, 870) AND srv_jobcodeid IN (13, 14)
I get the following result:
Expand|Select|Wrap|Line Numbers
  1. srv_id | srv_mcid | srv_jobcodeid | srv_bkdate
  2. 11     | 870        | 13                 | 1254790800
  3. 16     | 870        | 14                 | 1264361400
  4. 178    | 264        | 14                 | 1265997600
  5. 242    | 460        | 14                 | 1272153600
  6. 245    | 264        | 13                 | 1267299000
  7.  
Now The result set I wish to populate is
Expand|Select|Wrap|Line Numbers
  1. srv_id | srv_mcid | srv_jobcodeid | srv_bkdate
  2. 16     | 870        | 14                 | 1264361400
  3. 242    | 460        | 14                 | 1272153600
  4. 245    | 264        | 13                 | 1267299000
  5.  
This result set are the highest srv_bkdate for each srv_mcid in the given list
with srv_jobcodeid as 13 or 14.

What should be the sql statement that can provide this above result set?

In where condition the list of values for srv_mcid will vary and actually it will be populated dynamically in php.

I need your help to design the sql statement. I am not very sure if I need to write a subquery for this.
Feb 25 '10 #1
0 1235

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
5
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
5
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called...
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
9
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
4
by: Smokey Grindle | last post by:
What is the best way to write dynamic controls in ASP.NET 2.0?
1
by: zeebiggie | last post by:
Good morning I have a form with the controls in the insert statment below. table1 has an Auto increment primary key hence is omitted in the insert statment and form. Am getting the error It didnt...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.