你好第一个问题。 我有一个查询,在where子句中搜索传递id的列“description”,而不使用“id”列,它是如何实现的?
table parameters_companies
id description_parameter value_parameter id_company
1 BASE UTC 7 1
2保修10 1
3 BASE UTC 15 2
这个最令人感到努力,因为描述没有数字
SELECT
value_parameter
FROM
parameters_companies
WHERE
description_parameter = 1 AND
id_company = 1
但这很有效。为什么以及如何运作?使用它是一个好习惯吗?
SELECT
parameters_companies.value_parameter
FROM
parameters_companies
WHERE
parameters_companies.description_parameter = 1 AND
parameters_companies.id_company = 1
返回 value_parameter = 7 ,如果更改id_company = 2,则返回 value_parameter = 15 那么,参数_companies.description_parameter = 1搜索“id列”,然后用相同的“描述”列搜索?
编辑: 因为它被定义为我没有注意到的“枚举列”,我从不使用那种类型的列 你的时间是@CaptRespect @Up_One。
答案 0 :(得分:0)
他们都会毫无错误地运行,但不会返回任何内容! 你有什么意见?
mysql> create table parameters_companies(
-> id int,
-> description_parameter varchar(20),
-> value_parameter int,
-> id_company int
-> );
insert into parameters_companies values ('1','BASE UTC','7'Query OK, 0 rows affected (0.01 sec)
,mysql>
mysql> insert into parameters_companies values ('1','BASE UTC','7','1');
insert into paraQuery OK, 1 row affected (0.00 sec)
metermysql> insert into parameters_companies values ('2','WARRANTY','10','1');
intoQuery OK, 1 row affected (0.00 sec)
pmysql> insert into parameters_companies values ('3','BASE UTC','15','2');
Query OK, 1 row affected (0.00 sec)
ct * from parameters_companies;mysql>
mysql> select * from parameters_companies;
+------+-----------------------+-----------------+------------+
| id | description_parameter | value_parameter | id_company |
+------+-----------------------+-----------------+------------+
| 1 | BASE UTC | 7 | 1 |
| 2 | WARRANTY | 10 | 1 |
| 3 | BASE UTC | 15 | 2 |
+------+-----------------------+-----------------+------------+
3 rows in set (0.00 sec)
mysql>
mysql> SELECT
-> value_parameter
-> FROM
-> parameters_companies
-> WHERE
-> description_parameter = 1 AND
-> id_company = 1;
SELEEmpty set (0.00 sec)
mysql>
mysql>
mysql> SELECT
-> parameters_companies.value_parameter
-> FROM
-> parameters_companies
-> WHERE
-> parameters_companies.description_parameter = 1 AND
-> parameters_companies.id_company = 1;
Empty set (0.00 sec)
mysql>