0

What does SELECT 1 do, first I saw it in open source library when querying the login attempts. And of course there isn't any '1' column name in the table. What is the purpose of asking nonexistent column instead any real one? speed?

ProgZi
  • 1,028
  • 3
  • 14
  • 25
  • `select 1` selects the **value** `1` - no column involved. You need to be more specific if that does not answer your question – juergen d Jun 02 '16 at 18:35
  • 2
    it's for when you need to query for a row count, but don't want any of the data in the table. you can do `select 'some hardcoded fixed value' from sometable where somefield=somevalue`, just so you do get a result set. – Marc B Jun 02 '16 at 18:38
  • thank you for the link. It's definitely a duplicate. Next time will try search better. – ProgZi Jun 02 '16 at 18:43
  • @MarcB: If you're after a row count, why would you want a resultset that contains many records instead of doing `SELECT COUNT(*) FROM sometable WHERE somefield=somevalue` and obtaining a resultset that contains exactly your desired integer? – eggyal Jun 02 '16 at 18:43
  • 1
    @eggyal: mysql works properly with rowCount()-type functions, but not all dbs do. – Marc B Jun 02 '16 at 18:44
  • @MarcB: Good to know! Thanks. – eggyal Jun 02 '16 at 18:45

0 Answers0