Write query better - as it is only working for only 1 row in notice date WITH CURDATE? [closed] - mysql

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 2 years ago.
Improve this question
CREATE TRIGGER NOTICE_ISSUE
AFTER INSERT ON MEMBERS
FOR EACH ROW
INSERT INTO NOTICE (Ssn,LSSN,NOTICE_TYPE) VALUES
((SELECT Ssn from MEMBERS WHERE CURDATE() = NOTICE_DATE),
(SELECT LIB_SSN from MEMBERS WHERE CURDATE() = NOTICE_DATE),'RENEW YOUR MEMBERSHIP');

You are duplicating the select query, it would be better like this:
CREATE TRIGGER NOTICE_ISSUE AFTER INSERT
ON MEMBERS
FOR EACH ROW
INSERT INTO NOTICE (Ssn,LSSN,NOTICE_TYPE)
SELECT Ssn, LIB_SSN, 'RENEW YOUR MEMBERSHIP'
FROM MEMBERS
WHERE CURDATE() = NOTICE_DATE

Related

Updating a column with a Count of data from another column in the same 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 2 years ago.
Improve this question
As the title suggests, trying to take the count or possibly distinct count of a column, we call it year, to count the number of a years for an individual or populated ID and place it another column in the same table. Here is an idea of what I have so far and we want to update the table. Thank you.
Join group table to updated table directly:
UPDATE outputtable O JOIN
(SELECT personID, COUNT(DISTINCT year) AS countYear
FROM outputtable GROUP BY personID) temp ON O.personID=temp.personID
SET O.N=temp.countYear

Duplicate value while using Group By [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 3 years ago.
Improve this question
SELECT location,special,price FROM `tickets`
WHERE event = 'food' GROUP BY location
I think you want, (assuming its mysql) the following:
SELECT location, ANY_VALUE(special) special, ANY_VALUE(price) price
FROM tickets
WHERE event='food'
GROUP BY location ;
ANY_VALUE is strange aggregate function out of normal db standards that returns one of the values arbitarily.
If you wish to not have duplicate results in your rows you can choose only distinct result set.
SELECT DISTINCT location,special,price FROM tickets WHERE event = 'food' GROUP BY location

MySQL - Featch Records with limit in one table [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 6 years ago.
Improve this question
I have one table with 3 fields e.g.
Name, Team Name, Player_Number
there is multiple team and I want to fetch 2 member from each team.
Please share with fast solution.
Try this
select * from TableName s where (select count(*) from TableName a where a.TeamName = s.TeamName and a.Player_Number >= s.Player_Number) <= 2

String retrieve Function in SQL Query [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 7 years ago.
Improve this question
I am having a database with 2 columns employee and job.Job column contains character in each record.In that,I have to list the employees whose job is having last 3 characters as 'man'.I have to use only functions in SQL Query.
Use LIKE with wildcard:
SELECT *
FROM your_table
WHERE job_column_name LIKE '%man'
or using RIGHT
SELECT *
FROM your_table
WHERE RIGHT(job_column_name, 3) = 'man'
Answer For Question 4 is
SELECT *
FROM emp
WHERE SUBSTR(job,-3,3)='MAN';

Inserting data obtained via SELECT queries [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 8 years ago.
Improve this question
How can I do this correctly?
INSERT INTO tbl_task (`Assignedby`,`userID`)
SELECT ID FROM tbl_users WHERE UserName='$_GET[u]',
SELECT ID FROM tbl_users WHERE UserName='$_GET[at]'
Assuming you want to insert one row with two columns, I think you might want this:
INSERT INTO tbl_task(`Assignedby`, `userID`)
SELECT (SELECT ID FROM tbl_users WHERE UserName='$_GET[u]'),
(SELECT ID FROM tbl_users WHERE UserName='$_GET[at]');