October 24, 2024
Chicago 12, Melborne City, USA
SQL

Is there a way to substitute values in a SELECT with other data from the same table, occurring only under specific conditions?


I’ve got a set a of data that is basically this:

JobRow Hours Date JobID OriginalJobRow
101 4 2001-06-13 21777A Null
269 12 2004-11-30 24999A 101
270 10 2006-06-02 26888A Null

I’d like to find a way to select all information from my table, replacing JobID values where OriginalJobRow isn’t null with the JobID from the JobRow column that’s equal to the OriginalJobRow’s value, just for the purposes of the SELECT query.

In this example, I’d like my SELECT to return 21777A as the JobID for JobRow 269, since OriginalJobRow isn’t null on that row.

How might I accomplish this in a SELECT query?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video