Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
looking for something like
Select * FROM 'database' WHERE id = 1-40
something where I can select a number through a number like 1 through 40
multiple number select statement sql
SELECT * FROM database_table WHERE id BETWEEN 1 AND 40
This is an example page you can use: http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_between
The between operator is what you're looking for:
SELECT * FROM `database` WHERE id BETWEEN 1 AND 40
Try:
Select * FROM `tablename` WHERE id >= 1 AND id <= 40
Two possible ways for selecting range in DB:
Select * FROM `database.tablename` WHERE id BETWEEN 1 AND 40 ;
or
SELECT * FROM `DATABASE.TABLENAME` WHERE ID >= 1 AND <=40;
In case, you want to select multiple items which are not in range, you can use:
Select * FROM `database.tablename` WHERE id in (1,2,3,4,5,6.....40);
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Where do i put the Desc limit, doesnt work to put it at the end :/
$query = "SELECT * FROM category INNER JOIN videos ON videos.catid=category.id WHERE videos.favorite = '1' DESC LIMIT 5";
I only get warning
: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in
Try this:
SELECT * FROM category
INNER JOIN videos ON videos.catid=category.id
WHERE videos.favorite = '1'
ORDER BY category.id DESC LIMIT 5
I have used ORDER BY category.id, but you may use your preferable field.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm trying to find the 10 entries that are closest to the user with the following search:
$data_query = mysqli_query($db, "SELECT *
111.045 * DEGREES(ACOS(COS(RADIANS(latpoint))
* COS(RADIANS(latitude))
* COS(RADIANS(longpoint) - RADIANS(longitude))
+ SIN(RADIANS(latpoint))
* SIN(RADIANS(latitude)))) AS distance_in_km
FROM merchants
JOIN (
SELECT 33.889676 AS latpoint, 151.193024 AS longpoint
) AS p ON 1=1
ORDER BY distance_in_km
LIMIT 15");
However I'm getting the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '111.045 * DEGREES(ACOS(COS(RADIANS(latpoint))
* COS(RADIANS(la' at line 2
I tried changing SELECT * to SELECT latitude, longitude (with `` but Stack Overflow keeps messing up syntax) but it's not doing much.
I'm new to PHP and MySQL so I'm feeling pretty out of depth as to what could be going wrong here.
Cheers :)
If you want also select everything, then add comma after first *: SELECT *, 111.045 ...
If not, then remove first *
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a table(quiz). And the fields are id,question,answer, and level.
There Many questions for level 1, many questions for level 2 and so on. Please how do i query 10 rows based on the levels consecutively i.e
question1(level 1)
question2(level 2)
question3(level 3)
..to
question10(level 10)
this is what i have so far:
$con->prepare("SELECT*FROM quiz WHERE level IN (1,2,3,4,5.....10) limit 0,10");
but the result i get is only 10 questions on level 1. Please i also want it to be random
Here's an attempt, though perhaps it needs a subquery:
SELECT * FROM quiz
WHERE level BETWEEN 1 AND 10
GROUP BY level
ORDER BY RAND(), level
Second attempt:
SELECT * FROM
(
SELECT * FROM quiz
WHERE level BETWEEN 1 AND 10
ORDER BY RAND()
) tmp
GROUP BY level
ORDER BY level
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
This query runs well in mysql but cannot run in mssql. Why?
Don't judge me, I am new in mssql.
UPDATE cvcolumnlist
SET columnindex=columnindex+1
WHERE cvid=40 AND columnindex>=3
ORDER BY columnindex DESC
Error:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'order'.
You just need to remove ORDER clause. ORDER is pointless in an UPDATE statement.
UPDATE cvcolumnlist
SET columnindex=columnindex+1
WHERE cvid=40 AND columnindex>=3
You don't need at all the ORDER BY clause. this is only when SELECTing data from the database.
You may want to note that even though SQL is a language with a specified structure, different SQL engines may parse the query differently and use different syntax since a lot of the SQL functionality is not defined by the language.
for example in mysql you may use the LIMIT keyword for limiting the number of records that are returned and in mssql you may use ROWNUMBER and oracle uses the ROWNUM system.
UPDATE cvcolumnlist
SET columnindex = columnindex+1
WHERE cvid = 40
AND columnindex > 2
this should work
UPDATE [cvcolumnlist]
SET [columnindex] = [columnindex] + 1
WHERE [cvid] = 40 AND [columnindex] >= 3
I'm not sure if this applies. Most of my queries use something like this.
UPDATE [database].[dbo].[cvcolumnlist]
SET [columnindex] = [columnindex] + 1
WHERE [cvid] = 40 AND [columnindex] >= 3
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I want to delete rows from the database once a set amount of time has passed and the code I have isn't working and I am not sure where I have gone wrong. I plan to change the amount of time to 1 month but it is currently 1 minute for testing purposes.
require 'core/init.php';
$remOld = "DELETE * FROM `ratings` WHERE `ratedate` < NOW() - INTERVAL 1 MINUTE";
if ($remOld = $db->query($remOld)){
echo ('records removed');
}else{
echo ('didnt remove records');
}
Any pointers would be much appreciated.
Remove * from query and close open bracket in your query.
DELETE FROM `ratings` WHERE `ratedate` < (NOW() - INTERVAL 1 MINUTE)
try like this
$remOld = "DELETE FROM `ratings` WHERE `ratedate` < NOW() - INTERVAL '1 MINUTE'";
if ($remOld = $db->query($remOld)){
echo ('records removed');
}else{
echo ('didnt remove records');
}