Duplicate value while using Group By [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 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

Related

Is it possible to optimize this where clause? [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 5 months ago.
Improve this question
Can anyone help me with this? I have doubts about the below function; can I create a virtual column for this?
select as1.col,as1.col2,as1.col3 from
analytics.adjusted_sale_velocity
where
date(as1.created_datetime)=(
select
max(
date(created_datetime)
)
from
analytics.adjusted_sale_velocity
)
MySQL optimizer won't use an index once a column in the WHERE clause is wrapped with a function, date in your case.
Your query might be written a little different:
select as1.col,
as1.col2,
as1.col3
from adjusted_sale_velocity a
inner join ( select max(created_datetime) as created_datetime
from adjusted_sale_velocity
) as max_dt on left(a.created_datetime,10) = left(max_dt.created_datetime,10) ;
Try and let me know if it is faster.

how to use like clause in mysql to find grades [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
here is my query
SELECT distinct(DESIG_NAME)
FROM employees
WHERE GRADE like ("L0007", "L0008", "L0009");
I want to find grade of employee in one single statement
grade are level e.g., level7, level8, etc something like this
DISTINCT is not a function, and also you want WHERE IN (...):
SELECT DISTINCT DESIG_NAME
FROM employees
WHERE GRADE IN ('L0007', 'L0008', 'L0009');
SELECT distinct(DESIG_NAME) FROM employees where GRADE like 'L0007' or like 'L0008' or like 'L0009'

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

MySQL - Find the lowest unique value in 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
So I have a table for biddings, you can win the bidding by posting the lowest unique bid. So if 2 people place a bet of $1, none of them win, if 1 person places a bet of $2, this guy wins. But how can I check this in MySQL?
Assume your table has the bid value stored in the field name bet, then below is a worked solution:
SELECT * FROM YourTableName
WHERE bet = (SELECT MIN(bet) FROM YourTableName)
GROUP BY bet
HAVING COUNT(*) = 1;

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';