0

I'm currently preparing a major Program-Update and ran into following problem: I've got a Table in a Mysql-Database that looks (roughly) like this:

+-----------------------+--------------+------+-----+---------+----------------+
| Field                 | Type         | Null | Key | Default | Extra          |
+-----------------------+--------------+------+-----+---------+----------------+
| ID                    | int(15)      | NO   | PRI | NULL    | auto_increment |
| Versionnumber         | decimal(5,3) | NO   | UNI | NULL    |                |
| ChangeLog             | text         | NO   |     | NULL    |                |
| ReleaseDate           | datetime     | NO   |     | NULL    |                |
| Enabled               | tinyint(1)   | NO   |     | 1       |                |
+-----------------------+--------------+------+-----+---------+----------------+

Now I've changed the Columnname of the (former) Column 'ID' to 'VersionID'. This means the table now looks like this:

+-----------------------+--------------+------+-----+---------+----------------+
| Field                 | Type         | Null | Key | Default | Extra          |
+-----------------------+--------------+------+-----+---------+----------------+
| VersionID             | int(15)      | NO   | PRI | NULL    | auto_increment |
| Versionnumber         | decimal(5,3) | NO   | UNI | NULL    |                |
| ChangeLog             | text         | NO   |     | NULL    |                |
| ReleaseDate           | datetime     | NO   |     | NULL    |                |
| Enabled               | tinyint(1)   | NO   |     | 1       |                |
+-----------------------+--------------+------+-----+---------+----------------+

Now my question is the following: Is there a way to perform for example a 'SELECT' query without knowing exactly wether the Columnname is 'VersionID' or 'ID'? Something like (pseudo code)

SELECT (ID OR VersionID) AS VersionID FROM versions;

So what I'd need is something like a "Or-Clause" for the Columnname. Does something like that exist?

Thanks for your help!

4
  • what is the criteria for choosing one or the other? Commented Jun 18, 2012 at 12:00
  • 2
    No. You need to know the column names before you run the statement Commented Jun 18, 2012 at 12:00
  • I the column name dosen't exist it throws an error, even if you wrap it in a case statement. Commented Jun 18, 2012 at 12:19
  • There is no real 'criteria for choosing one or the other Column' since in fact only the one OR the other does exist. If both Columns may exist I would expect to get an error. Maybe again the background: I'm definitely changing the Column name from 'ID' to 'VersionID' at some point. My goal is to have the Mysql-Statement independent from that change. It should work as well with the 'ID-Column' as with the 'VersionID-Column'. Commented Jun 19, 2012 at 8:52

1 Answer 1

1

No I think You cannot do this . Use SELECT * FROM to know the name of the coloumn

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.