Select Not Exist [closed] - mysql

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)

Related

Find the max name [closed]

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 1 year ago.
Improve this question
I need to find the sum of the names and then choose the bigger.
I need to show that the max name is John smith because it's 4 times.
I guess you need the most repeated name. You may try below query -
SELECT writer, COUNT(*)
FROM YOUR_TABLE
GROUP BY writer
ORDER BY COUNT(writer) DESC
LIMIT 1;

SQL Display student record having maximum marks from other table [closed]

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 4 years ago.
Improve this question
student(sID,sNAME,sCLASS);
result(sID,subMARKS);
Actually, in MS-ACCESS, i am trying to this with equi join but getting wrong result. i'm writting my query like
SELECT stud.sID
, stud.sNAME
, stud.sCLASS
, result.sID
FROM student
, result
WHERE(SELECT MAX(subMARKS) FROM result)
It should display Ali record only because he is having maximum marks. but i am getting this kind of output as shown in picture below.
sID sNAME sCLASS
1 Ali BSC
2 Ahmad FSC
3 Asgar ICS
4 Akram BSC
SELECT T1.SID, T1.sname FROM student T1
LEFT JOIN resultT2 ON t1.sid=t2.sid
WHERE t2.submarks = (SELECT Max(submarks) FROM result);

SQL Query conditional row [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 8 years ago.
Improve this question
I have a table called 'list' that is like this:
system item1 exception
------------------------
A John 1
A Sarah 0
A Tim 1
A Blake 0
B Nikki 1
B Rick 0
C Jimbo 1
I am trying to build a query and I'm so terrible at it and I'm stuck. I want to return all rows unconditionally UNLESS system = 'A'. If system = 'A' then only return the rows where exception is true.
Thanks for your time.
What about this?
SELECT * FROM table WHERE system != 'A' OR exception = 1
SQL FIDDLE DEMO
select *
from list
where (system = 'A' and exception = 1)
or system <> 'A'
You can group conditions in the WHERE clause by enclosing each block in ()
http://www.techonthenet.com/sql/and_or.php

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

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'

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