roopurt18 Posted August 13, 2007 Share Posted August 13, 2007 I'd like to do something like: SELECT 'foo' AS bar From some_table But have a specific number of rows return, even though they'd all be identical. If I want 4 rows, I can attach a 'LIMIT 4' on the end of the query, but the table has to have at least 4 rows in it; what can I do if I'm not sure the table has that many rows? Thanks! Link to comment https://forums.phpfreaks.com/topic/64716-is-it-possible/ Share on other sites More sharing options...
SnowControl Posted August 13, 2007 Share Posted August 13, 2007 Just loop it 4 times then. for ($i=0 ; 4 > $i ; $i++) { echo "$foo"; } And if you dont want this if there are 4 or more rows in the sql result, just check it with a simple "if (mysql_num_rows($result) < 4)". Link to comment https://forums.phpfreaks.com/topic/64716-is-it-possible/#findComment-323029 Share on other sites More sharing options...
roopurt18 Posted August 14, 2007 Author Share Posted August 14, 2007 I have to do it without any programming logic, hence the reason I put it in the MySQL forum. Link to comment https://forums.phpfreaks.com/topic/64716-is-it-possible/#findComment-323240 Share on other sites More sharing options...
Illusion Posted August 14, 2007 Share Posted August 14, 2007 SELECT 'foo' AS bar From some_table EXISTS select count(*) as cnt from some_table having cnt >=4 Link to comment https://forums.phpfreaks.com/topic/64716-is-it-possible/#findComment-323527 Share on other sites More sharing options...
fenway Posted August 20, 2007 Share Posted August 20, 2007 SELECT 'foo' AS bar From some_table EXISTS select count(*) as cnt from some_table having cnt >=4 That's pretty much what I would suggest... I use mutex tables that have a lot of rows for that very purpose for other nitfy things, too. Link to comment https://forums.phpfreaks.com/topic/64716-is-it-possible/#findComment-329201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.