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! Quote Link to comment 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)". Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.