从MySQL获取双打印行,本机C

时间:2014-11-03 14:58:01

标签: mysql c

我有两列可以在两列中但不能同时存在的值。我将展示表中的exaple。


from_bank_number | to_bank_number |value

001              | 002            | 100
002              | 001            | 200
001              | 002            | 400

现在我将尝试打印出来。

mysql_query(conn, "SELECT from_bank_number, to_bank_number, value FROM some_table
                   WHERE from_bank_number = '001' OR to_bank_number = '001'");
res = mysql_use_result(conn);
while(row = mysql_fetch_row(res){
  printf("From: %s, To: %s, Value: %s\n",row[0], row[1], row[2]); 
}

当我只有3行时,这将打印6次。我如何防止它被双重打印?

From: 001, To:002, Value: 100
From: 002, To:001, Value: 200
From: 001, To:002, Value: 400
From: 001, To:002, Value: 100
From: 002, To:001, Value: 200
From: 001, To:002, Value: 400

我想摆脱重复

0 个答案:

没有答案