View Full Version : how to get rows from x to y with inner join
umen242
11-23-2008, 11:08 PM
Hello all i have this sql that bring me rows combained from 2 tables that is working fine , but now i like to bring only rows from x to y how can i implemnt this in this sql :
select
cars_categorys.cars_category_name_general_id ,
cars_list.car_id,
cars_list.category,
cars_list.cars_name from cars_categorys
INNER JOIN cars_list ON (cars_list.category = cars_categorys.cars_category_name_orig)";
oracleguy
11-24-2008, 01:36 AM
You can do that with the LIMIT clause. See http://dev.mysql.com/doc/refman/5.0/en/select.html#id2190320
umen242
11-24-2008, 06:54 AM
yeah i tried that so it will look like this :
select
cars_categorys.cars_category_name_general_id ,
cars_list.car_id,
cars_list.category,
cars_list.cars_name from cars_categorys LIMIT 5,10
INNER JOIN cars_list ON (cars_list.category = cars_categorys.cars_category_name_orig)";
but it gave me error
Fou-Lu
11-24-2008, 07:45 AM
Its funny, I actually prefer the oracle 'visual' models for this. Nice once you get used to them.
Here is the structure of a query (its at the top of the link oracleguy gave you):
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr, ...
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]
Its a lot of stuff, most of it you can ignore. But, notice the relative location of the LIMIT clause. Generally, its among (if not) the last item in you're query. Move it after the join clause.
brazenskies
11-24-2008, 11:04 AM
yeah i tried that so it will look like this :
but it gave me error
try...
select
cars_categorys.cars_category_name_general_id ,
cars_list.car_id,
cars_list.category,
cars_list.cars_name from cars_categorys
INNER JOIN cars_list ON (cars_list.category = cars_categorys.cars_category_name_orig)";
LIMIT 5,10
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.