/* You are working with a `products` table that contains the following columns:
| Column Name | Data Type | Description |
|---------------|-----------|------------------------------------------------------------------------------|
| `product_id` | INT | Unique ID for each product |
| `product_name`| VARCHAR | Product names that may have leading and trailing spaces or underscores (`_`) |
| `price` | INT | Price of the product |
Task:
Write a query to:
1. Remove leading and trailing underscores (`_`) and spaces from the `product_name` column using only the `TRIM()` function.
2. Display the cleaned `product_name` along with `product_id` and `price`.
Sample Input (products table):
| product_id | product_name | price |
|------------|---------------------|----------|
| 1 | __Laptop__ | 800.00 |
| 2 | Smartphone_ | 600.00 |
| 3 | __Tablet | 300.00 |
| 4 | Keyboard | 50.00 |
---
Expected Output:
| product_id | cleaned_product_name | price |
|------------|-----------------------|----------|
| 1 | Laptop | 800.00 |
| 2 | Smartphone | 600.00 |
| 3 | Tablet | 300.00 |
| 4 | Keyboard | 50.00 |
*/
CREATE TABLE products (
product_id INT,
product_name VARCHAR(15),
price INT
);
INSERT INTO products (product_id, product_name, price) VALUES
(1, '__Laptop__', 800.00),
(2, ' Smartphone_', 600.00),
(3, '__Tablet', 300.00),
(4, ' Keyboard ', 50.00),
(5, '__Monitor__', 250.00),
(6, ' Headphones_', 120.00),
(7, ' Mouse ', 30.00);
SELECT
product_id,
TRIM(BOTH ' ' FROM (TRIM(BOTH '_' FROM product_name))) AS cleaned_product_name,
price
FROM products;
To embed this program on your website, copy the following code and paste it into your website's HTML: