package main
import (
\"database/sql\"
\"fmt\"
\"github.com/gin-gonic/gin\"
)
func main() {
router := gin.New()
router.Use(gin.Logger())
First execute the select statement. Then with rows.Next()
check if there is a record on the database. If not, execute the insert query.
rows, err := db.Query("select sum(usercount) as usercount from ( select count(*) as usercount from category where name = 'construction' union all select count(*) as usercount from sub_category where name = 'construction' union all select count(*) as usercount from industry where name = 'construction' ) as usercounts;")
if err != nil {
log.Fatal(err)
}
if rows.Next() {
//exists
} else {
db.Query("INSERT INTO...")
}