1

Table 'section':

enter image description here

I am trying to create a query that does the following:

SELECT stop 
FROM section 
WHERE the id is the highest and the section is JPS_44-300-A-y10-1-1-1-H.

In the table above the result would be 1900HA080909. How can I do this using SQL?

jskidd3
  • 4,609
  • 15
  • 63
  • 127

4 Answers4

2

You can do this with the LIMIT function:

SELECT stop 
FROM section 
WHERE section='JPS_44-300-A-y10-1-1-1-H'
ORDER BY ID DESC
LIMIT 1;
Praxis Ashelin
  • 5,137
  • 2
  • 20
  • 46
1

Please try:

select * From YourTable a
where a.ID=(select MAX(ID) from YourTable b where b.Section=a.Section)
TechDo
  • 18,398
  • 3
  • 51
  • 64
0
SELECT stop FROM section
INNER JOIN (SELECT MAX(ID) FROM section WHERE section = 'JPS_44-300-A-y10-1-1-1-H') AS Tbl
 ON section.ID = Tbl.ID
Paul Lucaciu
  • 134
  • 3
0

Try like that

SELECT a.stop FROM section a WHERE a.id IN (
     SELECT MAX(id) FROM section b
    WHERE b.section = 'JPS_44-300-A-y10-1-1-1-H'
)
Wundwin Born
  • 3,467
  • 19
  • 37