•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 402,973 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,771 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 632 | Replies: 4
![]() |
•
•
Join Date: Jul 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
Can anyone help? I have 2 table each over 2M records and it is taking ages retrieving records.
1. A 'product' table that contains all products in store.
2. The second table is the 'offer' table which contains all offers related to the products (e.g price,store,product condition).
1. 'product' table fields
[pid, country, category, image]
2. 'offer' table fields
[offer_id, pid, store_id, condition, price, title, stock]
3. I need to get the image, min(price) and title for each new product.
Current Query:
Is there a better way to do this?
Thanks
Ee Loon
Can anyone help? I have 2 table each over 2M records and it is taking ages retrieving records.
1. A 'product' table that contains all products in store.
2. The second table is the 'offer' table which contains all offers related to the products (e.g price,store,product condition).
1. 'product' table fields
[pid, country, category, image]
2. 'offer' table fields
[offer_id, pid, store_id, condition, price, title, stock]
3. I need to get the image, min(price) and title for each new product.
Current Query:
sql Syntax (Toggle Plain Text)
SELECT * FROM product x, offer y WHERE x.pid=y.pid AND x.country = 'US' AND x.category LIKE 'auto|accessories' AND y.condition = 'new' AND y.price=( SELECT min(z.price) FROM pdt_offer z WHERE z.pid=y.pid AND z.quality='new' AND z.stock>0) AND y.stock >0 GROUP BY x.pid
Is there a better way to do this?
Thanks
Ee Loon
Last edited by peter_budo : Jul 11th, 2008 at 6:29 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Jun 2008
Posts: 40
Reputation:
Rep Power: 1
Solved Threads: 2
"SELECT *" e.g. select everything is always a bad idea.
To speed up, select only the things you want/need.
WOW! I look again at your query and cannot believe my eyes
because you select everything (*) from two tables!
Things you need to do:
1) Select what you want: e.g. "SELECT x.id,y.pid FROM blabla..."
2) Use indexes to speed up you queries, for more info about indexes look here:
- http://dev.mysql.com/doc/refman/5.0/...l-indexes.html
- http://www.tutorialized.com/tutorial...d-Indexes/7139
- and you'd better look here: http://www.tizag.com/mysqlTutorial/mysql-index.php
To speed up, select only the things you want/need.
WOW! I look again at your query and cannot believe my eyes
because you select everything (*) from two tables!Things you need to do:
1) Select what you want: e.g. "SELECT x.id,y.pid FROM blabla..."
2) Use indexes to speed up you queries, for more info about indexes look here:
- http://dev.mysql.com/doc/refman/5.0/...l-indexes.html
- http://www.tutorialized.com/tutorial...d-Indexes/7139
- and you'd better look here: http://www.tizag.com/mysqlTutorial/mysql-index.php
•
•
Join Date: Apr 2008
Posts: 295
Reputation:
Rep Power: 1
Solved Threads: 41
Hello elliaw,
Actually, this query is wrong! It should not work! Because of * (the sign of slackers) more than one column will be selected. Therefore, GROUP BY clause must contain more than as x.pid. If you don't get an error message, something is wrong with your data base system.
>>> 3. I need to get the image, min(price) and title for each new product.
It is a very good idea to follow kvdd's advice !
So select these three columns only and put them into GROUP BY clause. But attention: I really doubt heavily that that mysql would be able to manage an image (what type, a blob type?) in that place!
krs,
tesu
•
•
•
•
SELECT * FROM product x, offer y
WHERE x.pid=y.pid AND x.country = 'US' AND x.category like 'auto|accessories' AND y.condition = 'new'
AND y.price=( select min(z.price) from pdt_offer z
where z.pid=y.pid AND z.quality='new' AND z.stock>0)
AND y.stock >0
GROUP BY x.pid
Actually, this query is wrong! It should not work! Because of * (the sign of slackers) more than one column will be selected. Therefore, GROUP BY clause must contain more than as x.pid. If you don't get an error message, something is wrong with your data base system.
>>> 3. I need to get the image, min(price) and title for each new product.
It is a very good idea to follow kvdd's advice !
So select these three columns only and put them into GROUP BY clause. But attention: I really doubt heavily that that mysql would be able to manage an image (what type, a blob type?) in that place!
krs,
tesu
Information is moving—you know, nightly news is one way, of course, but it's also moving through the blogosphere and through the Internets. I promise you I will listen to what has been said here, even though I wasn't here. Ann and I will carry out this equivocal message to the world. I'm the master of low expectations.
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the MySQL Forum
- Previous Thread: IF THEN statement would not work
- Next Thread: One-To-Many Relationship (adding data)


Linear Mode