Sanjay Suthar Sanjay Suthar - 5 months ago 10
MySQL Question

A query with those fields, that are not required to get from huge fields within a table

           i want a query to display few fields from a table on webpage, but there are huge number of fields in that table, but i want such type of query that except few fields and displaying all remaining fields' data on web page.
Like: i have a table with 50 fields,


+--------+--------+--------+----------+     +----------+

|  Col1  |  Col2  |   Col3  |   Col4   | ---- |  Col50  |

|---------|---------|----------|-----------|       |-----------|

|           |            |            |              | ---- |             |

|           |            |            |              | ---- |             |
+-------+--------+--------+----------+     +----------+


but i want to display only 48 fields on that page. then any query that except those 2 fields name(Col49 and Col50) that are not required and show remaining data. So instead of writing:
SELECT Col1, Col2, Col3, Col4,...Col48 FROM table;
any alternate way to writing like that
SELECT *-(Col49,Col50) FROM table;

Answer

The best way to solve this is using view you can create view with those 18 columns and retrieve data form it

example

mysql> SELECT * FROM calls;
+----+------------+---------+
| id | date       | user_id |
+----+------------+---------+
|  1 | 2016-06-22 |       1 |
|  2 | 2016-06-22 |    NULL |
|  3 | 2016-06-22 |    NULL |
|  4 | 2016-06-23 |       2 |
|  5 | 2016-06-23 |       1 |
|  6 | 2016-06-23 |       1 |
|  7 | 2016-06-23 |    NULL |
+----+------------+---------+
7 rows in set (0.06 sec)

mysql> CREATE VIEW C_VIEW AS
    ->     SELECT id,date from calls;
Query OK, 0 rows affected (0.20 sec)

mysql> select * from C_VIEW;
+----+------------+
| id | date       |
+----+------------+
|  1 | 2016-06-22 |
|  2 | 2016-06-22 |
|  3 | 2016-06-22 |
|  4 | 2016-06-23 |
|  5 | 2016-06-23 |
|  6 | 2016-06-23 |
|  7 | 2016-06-23 |
+----+------------+
7 rows in set (0.00 sec)