DWilliams Posted August 4, 2010 Share Posted August 4, 2010 I just want to check if a row exists, I don't need to actually pull down any data. Right now I'm doing it like this: SELECT id FROM dbase WHERE id=$id After running that query I use mysql_num_rows to make sure it returned exactly one row, in which case I know the ID the user passed is valid. This isn't a big issue but for the sake of code readability I'd like to do something like this instead: SELECT NOTHING FROM dbase WHERE id=$id Is something like that possible? Link to comment https://forums.phpfreaks.com/topic/209806-is-it-possible-to-select-no-columns/ Share on other sites More sharing options...
shlumph Posted August 4, 2010 Share Posted August 4, 2010 Not to my knowledge, I usually do something like this to check if a row exists: SELECT COUNT(id) FROM table WHERE id = 2 Link to comment https://forums.phpfreaks.com/topic/209806-is-it-possible-to-select-no-columns/#findComment-1095181 Share on other sites More sharing options...
Pikachu2000 Posted August 4, 2010 Share Posted August 4, 2010 SELECT COUNT(`field`) is much more efficient than mysql_num_rows(), too. Link to comment https://forums.phpfreaks.com/topic/209806-is-it-possible-to-select-no-columns/#findComment-1095187 Share on other sites More sharing options...
awjudd Posted August 4, 2010 Share Posted August 4, 2010 SELECT 1 FROM table WHERE id = 2 That should work ... it just sets an arbitrary value that it will automatically grab ~juddster Link to comment https://forums.phpfreaks.com/topic/209806-is-it-possible-to-select-no-columns/#findComment-1095310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.