rohitbanerjee Posted April 14, 2012 Share Posted April 14, 2012 Hello, I can't really explain it so a example will be better: my_table: col1 col2 col3 col4 1 1 23 A 2 1 25 A 3 2 21 B 4 3 24 A 5 3 28 A the query is-- SELECT col3 FROM my_table WHERE col2=SELECT(MAX(col2) FROM my_table WHERE col4='A') For some reason this is illegal, I can also not use a limit because the number of rows is not known a priori. I remember seeing some sort of redirection in some other forum but would appreciate a more explicit response. Thanks This is not legal for some reason -- is there a way Link to comment https://forums.phpfreaks.com/topic/260942-mysql-search-query/ Share on other sites More sharing options...
l0gic Posted April 15, 2012 Share Posted April 15, 2012 Try.. SELECT col3 FROM my_table WHERE col2=(SELECT MAX(col2) FROM my_table WHERE col4='A') I'm pretty sure you just have '(' in the wrong place. Link to comment https://forums.phpfreaks.com/topic/260942-mysql-search-query/#findComment-1337450 Share on other sites More sharing options...
rohitbanerjee Posted April 15, 2012 Author Share Posted April 15, 2012 Wow, thanks -- makes me feel like an idiot Link to comment https://forums.phpfreaks.com/topic/260942-mysql-search-query/#findComment-1337451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.