I have a vessel tracking database schema with the following table for the schdual
CREATE TABLE IF NOT EXISTS `string_ports` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`string_id` int(10) NOT NULL,
`port_id` int(11) NOT NULL,
`port_order` int(10) NOT NULL,
`arriv_date` datetime NOT NULL,
`dep_date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 AUTO_INCREMENT=1 ;
the string_id is the id of the line for example I have 3 lines
Line 1 goes from port A to B to C to D
Line 2 goes from port A to C to D
Line 3 goes from port A to Z to B
I need a SQL query the if I want to search for lines going from port A to port C either directly or passing by other ports
so the SQL should say select strings from the string_ports where port C port_order > port A port order and they are on the same string
how can I write that SQl ??
Give this a try: