-2
4

1 回答 1

1

Sounds like these are in the same table? Is there any discriminator to tell you whether name holds an accountnumber or accountname?

In any even, with the following assumptions you could try an ugly self join:

  1. There are only two records with the record ID you want
  2. these are multiple columns in the same table holding different information in the ambiguous column names
  3. there is no better way to discriminate the record type

If so, something like this self-join should get you started:

SELECT t2.name as accountnumber from example_table as t1
INNER JOIN example_table as t2 on t1.recordID=t2.recordID
WHERE t1.name='$accountname'

EDIT Note - if my assumptions are correct and if this is data you are inheriting, I feel for you and you should look to improve it's structure. If you are designing it like this, you may want to think about it some more first.

EDIT 2

You probably want to put an index on the name column (this is the discriminator I would used based on your example).

Your query can be something like this:

SELECT t1.value as accountnumber,t2.value as accountName from example_table as t1
INNER JOIN example_table as t2 on t1.record=t2.record
WHERE t1.name='accountNumber' and t2.name='accountName'

See this SQL Fiddle: http://www.sqlfiddle.com/#!2/97c2f/1

于 2013-02-21T23:46:19.933 回答