mysql contracting 2 columns
How could I contract 2 columns, i.e. replace 2 columns with one?
EX:
| column a | column b | INTO | column c |
------------------------ ------------
| 1 | a | | 1-a |
| 2 | b | ? | 2-b |
| 3 | c | | 3-b |
With a single query?
I'm using 2 loops with :
for ($i=1; $i<=$x; $i++) {
for ($j=1; $j<=$y; $j++) {
sql ="SELECT * FROM table WHERE column 1 = '".$i."' AND column 2 = '".$j."'"
}
}
And would like to
sql ="SELECT * FR开发者_开发问答OM table WHERE column 3 = '".$i."-".$j."'"
Would this speed things up?
You can run a query like.
Select CONCAT(ColumnA,'-',ColumnB) AS ColumnC FROM MyTable;
Can you provide more information? Based off what you've asked so far, the following would do it:
SELECT CONCAT(a, '-', b) AS c
FROM theTable
CREATE TABLE temp (c VARCHAR(32)) SELECT CONCAT(a, "-", b) FROM foo;
精彩评论