简体   繁体   English

仅从数据库中获取唯一值作为 json 响应

[英]Only get unique values as json response from database

I have a database and understand in sql I can get unique values via: Select DISTINCT name, industry from database;我有一个数据库并了解 sql 我可以通过以下方式获取唯一值: Select DISTINCT name, industry from database; however when I access it via local host and look at the json response i get duplicate values from different times.但是,当我通过本地主机访问它并查看 json 响应时,我得到了不同时间的重复值。

code in VSCODE: VSCODE 中的代码:

  req.db.from('database').select("name","symbol")
    .then((rows) => {
      res.json({ "Error": false, "Message": "Success", "Database": rows })
    })
    .catch((err) => {
      console.log(err);
      res.json({ "Error": true, "Message": "Error in MYSQL query" })
    })
});

what do I need to alter to only receive the name and symbol of each response once and not for every single entry of that object in the database?我需要更改什么才能仅接收每个响应的名称和符号一次,而不是数据库中该 object 的每个条目?

ah simply.distinct.啊,简单的。不同的。 didn't work earlier for some reason but is working now.由于某种原因之前没有工作,但现在正在工作。 rookie:')菜鸟:')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM