Re: printing columns other than the search criteria

From: Axel Schwenke <axel.schwenke_at_gmx.de>
Date: Tue, 8 Nov 2016 12:42:21 +0100
Message-ID: <nvsdm1$omn$1_at_dont-email.me>


On 08.11.2016 05:32, Eric wrote:
> I have a mysql query like this
> Select * from archive where rain > '{0}

"SELECT *" is considered harmful [1]. Don't use it.

> but i want to print some other fields with it if rain is > 0

MySQL (or any database) is not about printing. It returns results. What you do with those, is your decision. You might print it or not, the database wouldn't care.

> So what i want is something like
> Select * from archive where rain > '{0}' print _at_datetime @baro

If you are interested only in the `datetime` and `baro` columns from your archive table, then tell that the database:

SELECT `datetime`, baro FROM archive WHERE rain > 0

Note 1: the quotes around datetime are necessary because DATETIME is a reserved word in MySQL. It's generally unadvisable to use reserved words as names for database objects.

Note 2: your syntax "where rain > '{0}'" looks fishy. Is the `rain` column really a string type? And why would you store '{0}' in it for "no rain"? Dp you really want to use a comparison operator for strings?

[1] http://www.parseerror.com/blog/select-*-is-evil Received on Tue Nov 08 2016 - 12:42:21 CET

Original text of this message