If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
Hi ,
I want to form a select query where i need to display the list of all names and their ids. Here if the name already exists i need to check whether if their date of birth and registration date is different.Only if they are different should i display them.
Table
First Name Last name DoB id Regis_Date
Kevin Patrick 25-05-1987 1 29-07-2009
Steve Prince 20-1-20009 2 30-07-2009
Kevin Patrick 25-05-1987 3 29-07-2009
Steve Prince 23-1-2009 4 29-07-2009
Output should be
Name id
Kevin Patrick 1
StevePrince 2
Steve Prince 4 (Since DOB is different)
please help me in forming the query.
SELECT t.firstname || t.lastname AS name
, t.id
FROM ( SELECT firstname
, lastname
, dob
, regis_date
, MIN(id) AS min_id
FROM daTable
GROUP
BY firstname
, lastname
, dob
, regis_date ) AS d
INNER
JOIN daTable AS t
ON t.firstname = d.firstname
AND t.lastname = d.lastname
AND t.dob = d.dob
AND t.regis_date = d.regis_date
AND t.id = d.min_id