how do i show all values from this table
------ --------- ------- -------- -----
| A | B | C | D | E |
------ --------- ------- -------- -----
| 2 | K | M | NULL | S |
| 3 | L | C | NULL | N |
| 4 | R | P | NULL | N |
| 5 | P | N | C | N |
| 6 | Y | Q | NULL | S |
| 7 | S | T | NULL | S |
| 8 | C | M | NULL | N |
| 9 | X | C | NULL | S |
| 10 | E | Q | NULL | N |
| 11 | A | C | NULL | S |
| 12 | C | NULL | C | N |
| 13 | F | Q | NULL | N |
| 14 | L | NULL | C | S |
| 15 | S | P | NULL | S |
------ --------- ------- -------- -----
to this.
show the first 8 values from column A, B and the 7 will be 5 in column A
SELECT A, B FROM letters LIMIT 8;
------ --------
| A | B |
------ --------
| 2 | K |
| 3 | L |
| 4 | R |
| 5 | P |
| 6 | Y |
| 5 | S |
| 8 | C |
| 9 | X |
------ --------
CodePudding user response:
You'll want to use a case expression or the if()
function. My preference is a case expression because it's more portable. Furthermore you'll need to supply an ORDER BY
clause since records in a table have no ordering.
SELECT CASE WHEN A=7 THEN 5 ELSE A END as A, B FROM letters ORDER BY letters.A LIMIT 8;