I need to know why you answer me as I need a query, I have a table of medical data and another of patients where two strings called id are not referenced or anything.
my medicals table.
+--------------------------------------+---------+---------------------+---------------+
| id | control | date | timestamp |
+--------------------------------------+---------+---------------------+---------------+
| 64f5fac0-96e8-11e6-938b-25cb5cd69242 | 2 | 2017-02-21 18:17:22 | 1487719042879 |
| 64f5fac0-96e8-11e6-938b-25cb5cd69242 | 1 | 2017-02-21 18:16:13 | 1487718961328 |
| 64f5fac0-96e8-11e6-938b-25cb5cd69242 | 0 | 2017-02-20 13:24:44 | 1487615084580 |
+--------------------------------------+---------+---------------------+---------------+
my patients table.
+--------------------------+--------------------------------------+---------------+-----------------+
| _id | id | nombres | numeroDocumento |
+--------------------------+--------------------------------------+---------------+-----------------+
| 5808fb0331a4dd0917e0abf1 | 64f5fac0-96e8-11e6-938b-25cb5cd69242 | jose geronimo | 17322147 |
+--------------------------+--------------------------------------+---------------+-----------------+
when I define a select
SELECT
id, control, date, timestamp
FROM
medicals
WHERE
id = '64f5fac0-96e8-11e6-938b-25cb5cd69242'
Group BY id
ORDER BY date DESC;
I have this as a result
+--------------------------------------+---------+---------------------+---------------+
| id | control | date | timestamp |
+--------------------------------------+---------+---------------------+---------------+
| 64f5fac0-96e8-11e6-938b-25cb5cd69242 | 1 | 2017-02-21 18:16:13 | 1487718961328 |
+--------------------------------------+---------+---------------------+---------------+
but I really need control (2)
+--------------------------------------+---------+---------------------+---------------+
| id | control | date | timestamp |
+--------------------------------------+---------+---------------------+---------------+
| 64f5fac0-96e8-11e6-938b-25cb5cd69242 | 2 | 2017-02-21 18:17:22 | 1487719042879 |
+--------------------------------------+---------+---------------------+---------------+
because I am grouping and ordering. but I need it in a slightly more complicated join I tried to place it.
SELECT
id, control, date, timestamp
FROM
medicals
WHERE
id = '64f5fac0-96e8-11e6-938b-25cb5cd69242'
order by date desc limit 1;
this is the result.
+--------------------------------------+---------+---------------------+---------------+
| id | control | date | timestamp |
+--------------------------------------+---------+---------------------+---------------+
| 64f5fac0-96e8-11e6-938b-25cb5cd69242 | 2 | 2017-02-21 18:17:22 | 1487719042879 |
+--------------------------------------+---------+---------------------+---------------+
but having this immersed in a join. just keep bringing me to that id control 1.
SELECT
numeroDocumento, nombres, control, medicals.id
FROM
patients
JOIN
medicals ON medicals.id = patients.id
WHERE
numeroDocumento = '17322147'
GROUP BY medicals.id
ORDER BY medicals.date DESC;
I have this as a result ..
+-----------------+---------------+---------+--------------------------------------+
| numeroDocumento | nombres | control | id |
+-----------------+---------------+---------+--------------------------------------+
| 17322147 | jose geronimo | 1 | 64f5fac0-96e8-11e6-938b-25cb5cd69242 |
+-----------------+---------------+---------+--------------------------------------+
I do not know what to do any help thanks in advance.