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 6 years ago.
Improve this question
I have a MySQL table named camp_details which has the following columns :
camp_id, camp_name, location, category, months , pattern
I have input fields which accepts values for location, category, months and pattern.
Based on the details provided, the table should sort according to the preferences (1:location , 2:Months , 3:pattern and 4:category).
That is, the table should display first containing location, next months and so on.
Kindly help me out in this.
just use this query
SELECT * FROM camp_details ORDER BY location , months,patter,category ;
or use DESC after column name which you want to sort in desc like
SELECT * FROM camp_details ORDER BY location , months DESC,patter,category ;
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 6 months ago.
Improve this question
I have table like this :
then i want query data like this :
how did to do that?
A subquery with group by should do the job:
select * from <table_name>
where (serial_number, attempt) in (select serial_number, max(attempt) from <table_name> group by serial_number)
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 1 year ago.
Improve this question
displays all data with certain field types, from the results of the query ...
I do queries in three tables, and only show data that has relations only, whereas I want to display everything even though there is no relation ...
the data that I have
I want to display the data as below
You need to use left join in this case
select a.position,c.nama from posisi a,kanaikan_posisi b,bana c
where a.id_position = b.id_position (+) and c.id_karyavan (+) = b.id_karyavan
order by a.id_position
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 6 years ago.
Improve this question
I have the following table where there are two relevant fields for searching, this is 'from' and 'to' and represents the range of employees and then the field 'InitialQMSDays' represents the value that I want to return.
So if I have a search value of say 6, it would look at that value and find it between the 6 - 10 row, and return 2.
any ideas?
SELECT InitialQMSDays
FROM my_table
WHERE 6 BETWEEN `From` AND `To`;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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
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.
Improve this question
I have an employee table with dob. Every month i want the list of current month birthday list.
I want the query for the current month employee birthday list. The dob file date like this '31-01-1986' and so on. Please help me to get this.
Since your dob column contains values like '31-01-1986', it must be a string datatype rather than a temporal one. This makes it difficult (and slow) to perform date operations such as you desire; you may be better off doing a pure string manipulation instead:
SELECT *
FROM employee
WHERE CAST(SUBSTRING(dob, 4, 2) AS UNSIGNED) = MONTH(CURRENT_DATE)
I recommend that you convert your table to use an appropriate temporal datatype, such as DATE:
ALTER TABLE employee ADD COLUMN new_dob DATE AFTER dob;
UPDATE employee SET new_dob = STR_TO_DATE(dob, '%d-%m-%Y');
ALTER TABLE employee DROP COLUMN dob, CHANGE new_dob dob DATE;
(Remember also to adjust indexes, as desired).
Note that you will accordingly need to update your application code to work with DATE literals, including the previous statement:
SELECT *
FROM employee
WHERE MONTH(dob) = MONTH(CURRENT_DATE)
Use this
WHERE month(dob) = month(now)
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
I'm using MySQL 5.5.25 on Mac 10.7.5. I have a number of usernames in my database table of the form
prefix
prefix1
prefix2
prefix3
I would like to write a query that returns the username with the highest number after the prefix. For example, in the above list, the query would return "prefix3". Is there a way to do this with a single query?
Try This:
SELECT username FROM TABLE_NAME ORDER BY convert(REPLACE(username, 'prefix', ''), signed) DESC LIMIT 1
Make sure to put the correct PREFIX, USERNAME column name as well as the correct TABLE name.
You can sort them alphabetically, descending. The top result will be the highest number, provided they're formatted in a consistent way.