Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have 3 mysql tables where I want to join them and get some results. When I am trying to do this I am geting error in mysql query syntax.
Here is my query syntax
select t.id,t.surveyId,t.questionId,t.ansId,t.freeText,t.respondentId,GROUP_CONCAT(CAST(t.ansId AS CHAR) SEPARATOR '~') as ansIds
from t_survey_responses t
join t_survey_questions q
where t.surveyId=336 and t.respondentId=724 and q.questionId=t.questionId
join t_repondents r on r.respondentSrcId=992762407447511
group by t.questionId
order by q.pageNo asc,q.sortOrder asc
Thanks
All the join conditions should come before the where clause:
select t.id,t.surveyId,t.questionId,t.ansId,t.freeText,t.respondentId,GROUP_CONCAT(CAST(t.ansId AS CHAR) SEPARATOR '~') as ansIds
from t_survey_responses t
join t_survey_questions q
join t_repondents r on r.respondentSrcId=992762407447511 -- Here!
where t.surveyId=336 and t.respondentId=724 and q.questionId=t.questionId
group by t.questionId
order by q.pageNo asc,q.sortOrder asc
I only see two tables in your from clause. Also, that group by isn't going to work when you are selecting so many columns. Could also be issues with the syntax of the cast and concatenation. Give us an error code/message!!!
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I want to make a report from 3 tables like this
SELECT transaksi.id_transaksi,transaksi.waktu_pengiriman,
pengirim.nama_pengirim,penerima.nama_penerima,
penerima.alamat_penerima,transaksi.harga,transaksi.status_pengiriman
FROM transaksi,pengirim,penerima
WHERE transaksi.waktu_pengiriman BETWEEN '2020-11-01' AND '2020-11-30'
I saw this answer on this forum that telling me I could SELECT 3 tables directly like that but the output unexpectedly duplicated so much. This is how it looks like
You are cross joining everything --- you want left joins... I'm guessing what the joins are but it would look something like this:
SELECT transaksi.id_transaksi,
transaksi.waktu_pengiriman,
pengirim.nama_pengirim,
penerima.nama_penerima,
penerima.alamat_penerima,
transaksi.harga,
transaksi.status_pengiriman
FROM transaksi
LEFT JOIN pengirim ON transaksi.id_pengirim = pengirim.id
LEFT JOIN penerima ON transaksi.id_penerima = penerima.id
WHERE transaksi.waktu_pengiriman BETWEEN '2020-11-01' AND '2020-11-30'
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 3 years ago.
Improve this question
I started using MySQL recently and I am facing a problem. I created two tables using create table command and inserted value in the table. These two commands were executed successfully. Then I tried using select command. When I try to execute this command it shows
"select" is not valid at this position for this server version, expecting: (, WITH
Here is my command:
select
*
from Employee,
where Gender="M" and NativePlace="Mumbai",
order Hobby by desc;
What is the reason for this?
There are a couple of syntax errors in your query, try this:
select
*
from Employee
where Gender='M' and NativePlace='Mumbai'
order by Hobby desc;
Remove the commas after Employee and "Mumbai" and you should be good.
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 6 years ago.
Improve this question
Im trying to pull out only "completed" orders
whats the problem in this select code?
('SELECT * FROM orders WHERE OrderUserID = :OrderUserID AND WHERE OrderStatus='Completed');
You have a single quote before the SELECT and then two more around the 'Completed'.
Replace the single quote at the start with a double, and put one at the end as well.
You also have an additional WHERE before your second condition. Normally you just say 'WHERE this AND this AND this'.
("SELECT * FROM orders WHERE OrderUserID = :OrderUserID AND OrderStatus='Completed'");
The query only needs one "WHERE" clause, unless using subqueries.
(SELECT * FROM orders WHERE OrderUserID = :OrderUserID AND OrderStatus='Completed');
Try this. You AND the conditions when you want to have multiple constraints on the retreiving data.
("SELECT * FROM orders WHERE OrderUserID = :OrderUserID AND OrderStatus='Completed'");
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
I can't seem to get this one working. I have two tables I want to join but one of the columns has a space in a few of the titles. I am trying the following code with out success.
I have not bought in the columns from the join yet because I want to test that I can make the join.
SELECT rcm.activitydatetime, rcm.'lead id', rcm.'new stage'
FROM customername_leads_by_lifecycle_stage_rcm AS rcm
INNER JOIN customername_leads AS leads
ON rcm.'lead id' = leads.ID;
The warning I get is
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 ''lead id', rcm.'new stage' FROM customername_leads_by_lifecycle_stage_rcm AS rcm INNE' at line 1
Any help is always appreciated, thanks!
Use backticks (`) rather than single quotes (') for column names
SELECT rcm.activitydatetime, rcm.`lead id`, rcm.`new stage`
FROM customername_leads_by_lifecycle_stage_rcm AS rcm
INNER JOIN customername_leads AS leads
ON rcm.`lead id` = leads.ID;
You may also consider renaming the columns so they don't have spaces.
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
Could anybody let me know that how can i fetch unique(PKID, Column1,column2) values from my_table in mySql?
You can either use Ozzyberto's way, which should work, or you could use GROUP BY:
SELECT PKID,Column1,Column2
FROM my_table
GROUP BY PKID,Column1,Column2
sqlfiddle demo
You must be looking for the DISTINCT keyword:
http://www.w3schools.com/sql/sql_distinct.asp
You would need the following query:
SELECT DISTINCT PKID, Column1,column2 FROM my_table