Search
 
SCRIPT & CODE EXAMPLE
 

SQL

codeigniter 3 get best-selling products

#You can use a SQL join between the tables on ProID, e.g.
select *
from products as p
inner join orderdetails as od
   on p.ProID = od.ProID
#You can use group by syntax to ensure you get distinct rows, e.g.

group by p.ProID
#Use aggregation function such as sum, count and avg to find out the totals in a select, e.g.

select sum(od.OrderQuantity) as total
#Use order by syntax to show the top answers, e.g.

order by sum(od.OrderQuantity) desc
#Use limit to show top n results, e.g.

limit 5
#Hopefully that gives you enough pointers to formulate the SQL yourself.

#notes, I've given the tables an alias to ensure you don't get conflicts between the column names. You can't reference total in your order statement due to the way SQL calculates the dataset. I've used an inner join, but you might want to look into left & right joins.
Comment

PREVIOUS NEXT
Code Example
Sql :: subquery postgresql syntax 
Sql :: Sql testing queries 
Sql :: get created time of database psql 8 
Sql :: alter check command 
Sql :: select from diffrent tables 
Sql :: mysql select bottom 10 rows 
Sql :: SQLite3::SQLException: table "categories" already exists: CREATE TABLE "categories" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL 
Sql :: utiliser 3 jointures mysql 
Sql :: pl sql constraint user function 
Sql :: SQL Copy Selected Columns Only 
Sql :: mysql exception output 
Sql :: distinct 
Sql :: sql select starts with 
Sql :: mysql create schgema 
Sql :: SQL sum column resulting from query 
Sql :: sql or operator 
Sql :: how to use mysql_tzinfo_to_sql on windows 
Sql :: Pattern matching alternative sql 
Sql :: get employees if not contains in sql 
Sql :: quantity count and group by some article 
Sql :: how to drop mili second in sql 
Sql :: oracle query archivemode 
Sql :: Get the First and Last Word from a String or Sentence 
Sql :: is there any limit of using joins in single mysql query ? 
Sql :: sql compound operators 
Sql :: sql count and addition by day 
Sql :: practice sql queries 
Sql :: sql count if 
Sql :: how to use db.execute 
Sql :: IlluminateDatabaseQueryExceptionSQLSTATE[HY000] [2002] No such file or directory 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =