Select 10 rows where sold='false' from SQL [closed] - mysql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm working on an IPN for PayPal, and I need to know how to select a certain amount of rows where sold='false'

The following should work:
SELECT * FROM your_table WHERE sold='false' LIMIT 10

select * from table where sold='false' limit 10
OR
select * from table where sold='false' limit M,N
this query fetches data starts from Mth row to N number of records
.

select top 10 * from table where sold='false'

Related

SELECT mysql query to get first 100 numbers (1-100) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
i want a mysql select query where i can get first 100 numbers starting from 1 and ending to 100 without CTE or any procedures just want a query only.
When I need a list of integers I use
SELECT help_keyword_id num
FROM mysql.help_keyword
HAVING num BETWEEN 1 AND 100
ORDER BY 1;

Simple SQL Union 2 queries on the same table [closed]

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 7 years ago.
Improve this question
Trying to get all rows where userid = 'me'
Then 2 newest rows where userid <> 'me'
Items:
Userid time
other2 11
other3 10
me 10
me 8
other1 8
other3 7
me 6
would return
Userid time
me 10
me 8
me 6
other2 11
other3 10
The results don't have to be in any order
(SELECT * FROM Items WHERE userid='me' )
UNION ALL
(SELECT * FROM Items WHERE userid<>'me'
ORDER BY time DESC LIMIT 2)
This only outputs 2 rows
The sql was correct as shown above
(SELECT * FROM Items WHERE userid='me' )
UNION ALL
(SELECT * FROM Items WHERE userid<>'me'
ORDER BY time DESC LIMIT 2)
Union All concatenates the two queries, and the parenthesis allow different WHERE/ORDER BY/LIMIT clauses.
Demonstrated here:
http://sqlfiddle.com/#!9/ca405/1/0

MySQL 2 counts in query [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have this table, answers:
user
question
rightAnswer
ab
1
0
bc
1
1
de
1
1
bc
2
1
ab
2
1
de
2
0
fx
2
1
I want to create a view in phpMyAdmin that can display the question number, the total number of answers to that question and the number of right answers to that question.
I would like it to look like:
question
total answers
right answers
1
3
2
2
4
3
Could anyone help me to make this view? How do I create the query? I have tried something about count(*) where rightAnswer=1, but I cannot get it to count BOTH the total number of answers and the number of answers of each question.
try something like this:
select question,count(*),sum(rightAnswer)
from TABLE
group by question
order by question
select question, count(*) as total_answers, sum(rightAnswer) as right_answers
from your_table
group by question
order by question
Using ms sql syntax:
SELECT Question, totalAnswers.Total, rightAnswers.correct
FROM answers AS a
INNER JOIN (
SELECT Question, COUNT(rightanswer) AS correct
FROM answers
WHERE rightanswer = 1
GROUP BY Question
) rightAnswers
ON a.Question = rightAnswers.QUestion
INNER JOIN (
SELECT Question, COUNT(rightanswer) AS total
FROM answers
GROUP BY Question
) totalAnswers
ON a.Question = rightAnswers.QUestion

select couple of random rows by different criteria in one query [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to select 4 random rows from a table where level = 1 and 4 random rows from the same table where level=2. How can I do this in 1 query ?
select * from (select * from your_table
where level = 1 order by rand() limit 4) x
union all
select * from (select * from your_table
where level = 2 order by rand() limit 4) y
try like this...
SELECT product_id, title, description FROM products WHERE active = 1 AND stock > 0 ORDER BY RAND() LIMIT 4;

Select Not Exist [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
this table called category
I want to select records with Sid=3 AND Bid =0 that not duplicated with Sid=3 AND Bid=8
(I want to select the red record in the image)
http://img27.imageshack.us/img27/8127/6opr.jpg
You can use a subquery like this :
SELECT * FROM Category WHERE Sid = 3 AND Bid = 0
AND Name NOT IN (SELECT Name FROM Category WHERE Sid = 3 AND Bid = 8)