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
I have the following two MySQL tables for emails...
mail_emails
Columns: id, folder, user
mail_folders
Columns: id, name, user
I want to use only a single MySQL query to fetch the folder names and the number of emails per folder. Presuming the user id is 1, what would be the most efficient approach to this goal?
I am not exactly sure of your database structure. But this should give you an idea.
SELECT *, count(e.folder) totalMail FROM mail_folders f INNER JOIN mail_emails e on e.folder = f.name WHERE f.user = '1' GROUP BY e.folder
I am assuming that the name field in the mail_folders table is the same value that will be stored in folder field of mail_emails table.
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 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 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 ;
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 7 years ago.
Improve this question
I have a table named 'User' and it has an autoincremented field userID.
I want to retrieve that userID in my servlet. There is no such parameter/field referred to on that respective HTML. How can I use that userID in my servlet?
I would say your question is far to broad for a definite answer mate but here goes my best guess.
I assume you run this table and data in mysql since you tagged this as mysql.
you can retrieve the data you wish with the query as below:
SELECT userID FROM User;
Note: If you have more than 1 this will return all of them. If you want to limit this down to 1 you will need to match that to another unique parameter in your table. For example lets say you have a column in User table called "telephone"
the query would be:
SELECT userID FROM User WHERE telephone = '1234567890';
You can then display the result in your html, depending on what language you use to execute this query with.
Hope this helps
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
I am learning sql at the moment and i come across exist condition. What i know clearly is that and exist checks for the result of the sub query and if the result is TRUE outer query runs and if it is false outer query does not run.
But i am unable to understand is that how where clause fits in all this and how does it relates to outer query.
Please also explains to me what exactly happens after exist condition checks to TRUE.
Here is an example on how EXISTS relates with the outside query:
SELECT *
FROM classes a
WHERE EXISTS (
SELECT 1
FROM student b
WHERE b.a_id = a.id -- Here you relate inner query with outside query
)
You want to get the records in classes where there are at least one record in table students with a foreign key of the id in table classes.
You relate them in the WHERE of the inner query.
If there are no students in that class, the outside query will not return that class.