Im making a chat application with node js and mysql and i need to get all the data between sender id and receiver id but im stuck in that .
Need to get all the communications between these 2 id
SELECT * FROM messages WHERE (sender = '" + request.body.sender + "' AND receiver = '" + request.body.receiver + "') OR (sender = '" + request.body.receiver + "' AND receiver = '" + request.body.sender + "')"
I am trying to use GROUP_CONCAT with a custom delimiter which is working:
private val mainQuery = "SELECT re.ENTRY_ID, " +
"GROUP_CONCAT(re._ID, '§') AS read_id, " +
"GROUP_CONCAT(re.READING_ELEMENT, '§') AS read_element, " +
"GROUP_CONCAT(re.FURIGANA_BOTTOM, '§') AS furigana_bottom, " +
"GROUP_CONCAT(re.FURIGANA_TOP, '§') AS furigana_top, " +
"GROUP_CONCAT(re.NO_KANJI, '§') AS no_kanji, " +
"GROUP_CONCAT(re.READING_COMMONNESS, '§') AS read_commonness, " +
"GROUP_CONCAT(re.READING_RELATION, '§') AS read_rel, " +
"GROUP_CONCAT(se.POS, '§') AS pos, " +
"GROUP_CONCAT(se.GLOSS, '§') AS gloss, " +
"GROUP_CONCAT(se.FIELD, '§') AS field, " +
"GROUP_CONCAT(se.DIALECT, '§') AS dialect, " +
"GROUP_CONCAT(se.INFORMATION, '§') AS info " +
"FROM Jmdict_Reading_Element AS re " +
"JOIN Jmdict_Sense_Element AS se ON re.ENTRY_ID = se.ENTRY_ID " +
"JOIN Jmdict_Kanji_Element AS ke ON re.ENTRY_ID = ke.ENTRY_ID "
private val kanjiQuery = mainQuery +
"WHERE ke.ENTRY_ID IN (SELECT ENTRY_ID FROM Jmdict_Kanji_Element WHERE KANJI_ELEMENT LIKE ?) " +
"GROUP BY re.ENTRY_ID " +
"ORDER BY (CASE WHEN ke.KANJI_ELEMENT = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN ke.KANJI_ELEMENT LIKE ? THEN 1 ELSE 2 END), " +
"(CASE WHEN se.GLOSS = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN se.GLOSS LIKE ? THEN 1 ELSE 2 END), re.READING_ELEMENT"
private val kanaAndEnglishQuery = mainQuery +
"WHERE re.ENTRY_ID IN (SELECT ENTRY_ID FROM Jmdict_Reading_Element WHERE READING_ELEMENT LIKE ?) " +
"OR re.ENTRY_ID IN (SELECT ENTRY_ID FROM Jmdict_Sense_Element WHERE GLOSS LIKE ?) " +
"GROUP BY re.ENTRY_ID " +
"ORDER BY (CASE WHEN re.READING_ELEMENT = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN re.READING_ELEMENT LIKE ? THEN 1 ELSE 2 END), " +
"(CASE WHEN se.GLOSS = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN se.GLOSS LIKE ? THEN 1 ELSE 2 END), re.READING_ELEMENT"
However, as soon as I try to add DISTINCT: GROUP_CONCAT(DISTINCT re.READING_ELEMENT, '§') AS read_element, it no longer works: DISTINCT aggregates must have exactly one argument.
I am trying to remove the duplicates found. (Even though they aren't in the database... if there is
something that is in the query that is causing this please answer with that because that would also solve the problem)
SQLite does not support the separator argument if you use DISTINCT inside GROUP_CONCAT() (maybe it's a bug).
What you can do is:
REPLACE(GROUP_CONCAT(DISTINCT re.READING_ELEMENT), ',', '§')
to replace all the commas (default delimiter) with the delimiter of your choice.
If the column contains commas, then a (dirty) solution is to replace them with a character that you know does not exist, say '*':
REPLACE(REPLACE(GROUP_CONCAT(DISTINCT REPLACE(re.READING_ELEMENT, ',', '*')), ',', '§'), '*', ',')
get the distinct() first using a subquery, before performing group_concat(). Since we will be getting distinct on re.READING_ELEMENT, will be grouping by this column instead.
private val mainQuery = "SELECT re.ENTRY_ID, " +
"GROUP_CONCAT(t1._ID, '§') AS read_id, " +
"GROUP_CONCAT(t1.READING_ELEMENT, '§') AS read_element, " +
"GROUP_CONCAT(t1.FURIGANA_BOTTOM, '§') AS furigana_bottom, " +
"GROUP_CONCAT(t1.FURIGANA_TOP, '§') AS furigana_top, " +
"GROUP_CONCAT(t1.NO_KANJI, '§') AS no_kanji, " +
"GROUP_CONCAT(t1.READING_COMMONNESS, '§') AS read_commonness, " +
"GROUP_CONCAT(t1.READING_RELATION, '§') AS read_rel, " +
"GROUP_CONCAT(t1.POS, '§') AS pos, " +
"GROUP_CONCAT(t1.GLOSS, '§') AS gloss, " +
"GROUP_CONCAT(t1.FIELD, '§') AS field, " +
"GROUP_CONCAT(t1.DIALECT, '§') AS dialect, " +
"GROUP_CONCAT(t1.INFORMATION, '§') AS info FROM " +
"(SELECT re._ID, re.READING_ELEMENT, re.FURIGANA_BOTTOM, re.FURIGANA_TOP, re.NO_KANJI " +
", re.READING_COMMONNESS, re.READING_RELATION, se.POS, se.GLOSS, se.FIELD, se.DIALECT, se.INFORMATION " +
"FROM Jmdict_Reading_Element AS re " +
"JOIN Jmdict_Sense_Element AS se ON re.ENTRY_ID = se.ENTRY_ID " +
"JOIN Jmdict_Kanji_Element AS ke ON re.ENTRY_ID = ke.ENTRY_ID"
private val kanjiQuery = mainQuery +
" WHERE ke.ENTRY_ID IN (SELECT ENTRY_ID FROM Jmdict_Kanji_Element WHERE KANJI_ELEMENT LIKE ?) GROUP BY(re.READING_ELEMENT) ) t1" +
"GROUP BY t1.ENTRY_ID " +
"ORDER BY (CASE WHEN t1.KANJI_ELEMENT = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN t1.KANJI_ELEMENT LIKE ? THEN 1 ELSE 2 END), " +
"(CASE WHEN t1.GLOSS = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN t1.GLOSS LIKE ? THEN 1 ELSE 2 END), t1.READING_ELEMENT"
private val kanaAndEnglishQuery = mainQuery +
" WHERE re.ENTRY_ID IN (SELECT ENTRY_ID FROM Jmdict_Reading_Element WHERE READING_ELEMENT LIKE ?) " +
"OR re.ENTRY_ID IN (SELECT ENTRY_ID FROM Jmdict_Sense_Element WHERE GLOSS LIKE ?) GROUP BY(re.READING_ELEMENT)) t1" +
"GROUP BY t1.ENTRY_ID" +
"ORDER BY (CASE WHEN t1.READING_ELEMENT = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN t1.READING_ELEMENT LIKE ? THEN 1 ELSE 2 END), " +
"(CASE WHEN t1.GLOSS = ? THEN 1 ELSE 2 END), " +
"(CASE WHEN t1.GLOSS LIKE ? THEN 1 ELSE 2 END), t1.READING_ELEMENT"
I am getting this error:
Syntax error (missing operator) in query expression '10'
My code:
string MySQL3 = "Update RegisterDatabase Set ";
MySQL3 += "uName ='" + Request.Form["uname"] + "', pName ='" + Request.Form["pname"] + "', idNumber ='" + Request.Form["id"] + "', age =" + Request.Form["age"] + "', pass ='" + Request.Form["pass"] + "', email ='" + Request.Form["email"] + "'";
MySQL3 += " Where uName ='" + Session["uname"];
System.Data.OleDb.OleDbCommand o_command3 = new System.Data.OleDb.OleDbCommand(MySQL3, o_con);
o_con.Open();
o_command3.ExecuteNonQuery();
o_con.Close();
BTW I know my code is prone to SQL Injection attack, but this is for my school project so it doesn't really matter.
The problem is here
age =" + Request.Form["age"] + "+ "'
It should be
age =" + Request.Form["age"] + ", pass =
and
MySQL3 += " Where uName ='" + Session["uname"];
should be
MySQL3 += " Where uName ='" + Session["uname"] +"'";
String MySQL3 = "Update RegisterDatabase Set ";
MySQL3 += "uName ='" + Request.Form["uname"] + "', pName ='" + Request.Form["pname"] + "', idNumber ='" + Request.Form["id"] + "', age ='" + Request.Form["age"] + "', pass ='" + Request.Form["pass"] + "', email ='" + Request.Form["email"] + "'";
MySQL3 += " Where uName ='" + Session["uname"];
Just try above code.
Hope this will helps.
Can Any one help me to write a query by which i can fetch a record with specific date having specific value of a column. this query given below giving records with specific value but not filtering the date.
sql = "Select * from solarleads where Phone = '" + c_id.Text + "' OR AgentName Like '" + c_id.Text + "%' OR CallStatus Like '%" + c_id.Text + "%' OR CenterId = '" + c_id.Text + "' And Date >= '" + date1.Text + "' AND Date <='" + date2.Text + "' ORDER BY Id DESC ;";
You need to bracket the set of ORed conditions.
sql = "Select * from solarleads
where ( Phone = '" + c_id.Text + "' OR AgentName Like '" + c_id.Text + "%'
OR CallStatus Like '%" + c_id.Text + "%'
OR CenterId = '" + c_id.Text + "' )
And Date >= '" + date1.Text + "' AND Date <='" + date2.Text + "'
ORDER BY Id DESC ;"
Separate and condition by parenthesis, like -
sql = "Select * from solarleads where " +
"(Phone = '" + c_id.Text + "' " +
"OR AgentName Like '" + c_id.Text + "%' " +
"OR CallStatus Like '%" + c_id.Text + "%' " +
"OR CenterId = '" + c_id.Text + "' ) " +
"(And Date >= '" + date1.Text + "' AND Date <='" + date2.Text + "' )" +
"ORDER BY Id DESC ;";
Also check - Mysql or/and precedence?
INSERT INTO `idt_lookup`(`idt_resources`, `idt_lookup_name`, `idt_lookup_tbl_name`, `idt_lookup_key_col`, `idt_lookup_val_col`, `last_upd_by`, `last_upd_datetime_utc`) VALUES ('" + resourceId + "','" + roltbl + "','" + roltbl + "','" + rolid + "','" + rolname + "','1','" + date1 + "')
SELECT MAX(`idt_lookup_id`) AS maxid FROM `idt_lookup
How can i join these two queries. Is this possible?
Try Sample Query:-
$insertQuery = "
INSERT INTO owner_business_media
(business_id, sequence, type, filename, title, secret)
SELECT
'".intval($_GET['businessid'])."',
(SELECT MAX(obm.sequence)+1 FROM owner_business_media obm WHERE obm.business_id=".intval($_GET['businessid']).") AS next,
'$type',
'$fullfile',
'$filename',
'1'
";
Hope this will help...!!