I try to create a MySQL Statement with multiple SQL Statements.
What i trying to do:
I get two tables, project
& jiraissue
.
Table: project
Columns:
ID decimal(18,0) PK
pname varchar(255)
URL varchar(255)
LEAD varchar(255)
DESCRIPTION text
pkey varchar(255)
pcounter decimal(18,0)
ASSIGNEETYPE decimal(18,0)
Table: jiraissue
Columns:
ID decimal(18,0) PK
pkey varchar(255)
PROJECT decimal(18,0)
REPORTER varchar(255)
ASSIGNEE varchar(255)
issuetype varchar(255)
SUMMARY varchar(255)
DESCRIPTION longtext
ENVIRONMENT longtext
PRIORITY varchar(255)
RESOLUTION varchar(255)
issuestatus varchar(255)
CREATED datetime
UPDATED datetime
DUEDATE datetime
VOTES decimal(18,0)
TIMEORIGINALESTIMATE decimal(18,0)
TIMEESTIMATE decimal(18,0)
TIMESPENT decimal(18,0)
WORKFLOW_ID decimal(18,0)
SECURITY decimal(18,0)
FIXFOR decimal(18,0)
COMPONENT decimal(18,0)
My goal is to get the names of the projects (project.pname) which newest issue is updated before 2012 (jiraissue.UPDATED).
Example:
I get a Project ABC which newest issue was update in 21.11.2012. The other Project XYZ's newest issue was updated last in 08.12.2011.
So my SQL Script should give me the name of the second project XYZ but not the first ABC
A working script to find out which issue is the newest with a STATIC project ID comes here:
SELECT
pkey
FROM
jiraissue
WHERE
UPDATED = (SELECT
max(UPDATED)
FROM
jiraissue
WHERE
PROJECT = 10472)
But how is the script now, when i want the project names of ALL these projects? All of my trys take a lot of processing time and give a undefinied error back...
EDIT: Now i get the following code:
select
p.pname, j.pkey
from
project p
inner join
jiraissue j ON j.ID = (select
PROJECT
from
jiraissue
where
UPDATED = (SELECT
max(UPDATED)
from
jiraissue))
AND p.ID = j.PROJECT
The Result is but just the first project with the lowest key... How can i browse ALL Projects?
EDIT:
select
p.pname, j.pkey, j.UPDATED
from
project p
inner join
jiraissue j
where
j.ID = (select
PROJECT
from
jiraissue
where
UPDATED = (SELECT
max(UPDATED)
from
jiraissue
where
UPDATED < '2012-01-01 00:00:00'))
and p.ID = j.PROJECT
It displays all what i want. But just the first project. So i need ALL projects!! How can i select not just 1 project but all projects?