![]() |
mysql query, help needed,
this is the original query and it throws whole data,
$result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 ORDER BY encoded_date"); so i want to limit the values from column record_num from say 1 to 20k. record_num is kind of index so i can limit the output . how do i do this ? thanks for your time.:helpme |
The best way to fix this is to stop using mysql.
:2 cents: |
Quote:
thanks for your time. have a gr8 weekend. |
add "AND record_num<20000" to the WHERE clause? or am I misunderstanding what you want?
|
$result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 AND record_num<20000 ORDER BY encoded_date");
BTW defining an alias for content_views.views as "views" is pretty pointless in this query. |
Quote:
so for fetching 20k to 40k should i do something like this . $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 AND record_num>20000 AND record_num<40000 ORDER BY encoded_date"); thanks for your time. |
Quote:
now i got the idea of using AND, thanks a lot. |
If you are trying to obtain a range, just use mysql's range function:
May times the programmer needs to find out some specific data which lies in the particular range of values but there is not any predefined function in MySQL but we can also find that particular range's data from the database in MySQL using BETWEEN and AND clauses or write your own simple query. Syntax: exp BETWEEN min_value AND max_value The above syntax is equivalent to the expression (min_value <= exp AND exp <= max_value). In the following example we will describe you that how one can find out specific data lying between some range. To fire query we must have some data into a table therefore we will first create a table and fill some data into it. Example: SELECT id, name, subject from mca where mca.id BETWEEN 2 AND 5; Above query can also be written as below: SELECT id, name, subject from mca where ( mca.id >=2 && mca.id <=5); |
Quote:
because of ur explaination i have found something very useful for me., Code:
mysql> SELECT 1 BETWEEN 2 AND 3; now my query looks like this., with start point and exnd point., $result = mysql_query("SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 AND record_num BETWEEN 1000 AND 1200 ORDER BY encoded_date"); thanks a lot.:thumbsup |
you have a flaw in your logic though. What if encoding is not done in the row records are added? Then your record_num 2001 might be encoded before record_num 2000, and your order by logic becomes useless..
|
Quote:
SELECT content.*, content_views.views AS views FROM content, content_views WHERE content_views.content = content.record_num AND content.approved = 2 AND content.enabled = 1 ORDER BY encoded_date LIMIT 0,1000 LIMIT 0,1000 - get the first 1000 entries LIMIT 1000,1000 - get the 2nd set of 1000 entries LIMIT 2000,1000 - get the 3rd set of 1000 entries If you don't use LIMIT, then really, you're ORDER BY has no meaning. |
All times are GMT -7. The time now is 11:20 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc