![]() |
A quick SQL question
Say for example you have 10 000 products in a table and they all fall into 30 categories.
Now you want to select 50 products from a couple of those categories (could be any amount between 1-30 of those categories pending on how many the user wants). Do you, A: make one select query to get all 10 000 products and filter the results yourself. or B: make one select query per category(meaning 1-30 queries) and limit each query to 50. Which would be more efficient? |
If on train going 40 mph. gets a 30 min headstart, when will the train going 55 catch up?
|
B as long as your query is efficient.
|
B and i dont thinks you wanna show 1000 products at the same time... 20 cats times 50 products .....so B
|
OR depending on your skill level you use joins and such and if your tables are setup right you might be able to pull all the information you need in a single query with GROUP BY and other similar SQL functions. Do reasearch about the DB type and understand when and when not to use database normalization.
All really depends on the layout and what you are trying to get specifically from it. Andy |
yeah. think i'll write both functions and run 'em up against each other.
and yes i do have to much time on hand :) I need a new project after the succesful launch of http://webmasters.za.net |
ok. you have all the products along with all the category id's in one table. so you want to select 50 products per categoryid, but it's not that easy.
|
Quote:
|
You seem to keep asking questions and its a bit uncclear exactly what you want. However keep in mind one thing ..... let sql do the work as opposed to PHP,Perl, etc. Dont pull out all the data , then sort - you want to sort , etc. then pass the relevant data into your program. You will always get better results if you do the sorting, etc. within sql. If you cant create a query for it, you will need to go back and redesign your db (write it down first , dont create as you go). If you wing it you will run into issues down the road , be they performance, normalization, etc.
Rory :helpme |
thanks allot guys.
i was a bit unsure about 20 queries or one hughe one. |
All times are GMT -7. The time now is 09:07 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123