GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   A quick SQL question (https://gfy.com/showthread.php?t=86555)

Bad B0y 11-05-2002 02:17 PM

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?

Machete_ 11-05-2002 02:26 PM

If on train going 40 mph. gets a 30 min headstart, when will the train going 55 catch up?

Alky 11-05-2002 02:30 PM

B as long as your query is efficient.

grumpy 11-05-2002 02:54 PM

B and i dont thinks you wanna show 1000 products at the same time... 20 cats times 50 products .....so B

AcidMax 11-05-2002 02:56 PM

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

Bad B0y 11-05-2002 03:00 PM

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

Bad B0y 11-05-2002 03:11 PM

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.

Penrod 11-05-2002 03:13 PM

Quote:

Originally posted by ebus_dk
If on train going 40 mph. gets a 30 min headstart, when will the train going 55 catch up?
not long

Rory 11-05-2002 03:23 PM

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

Bad B0y 11-05-2002 03:31 PM

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