If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > possiblility of reffering to the reslut of query with another query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-23-04, 07:25
bjozefiak bjozefiak is offline
Registered User
 
Join Date: Nov 2004
Posts: 3
possiblility of reffering to the reslut of query with another query

Hi,
how are u?? i'm beginner and need Your help.

I am asking about possiblility of reffering to the reslut of query below with another query. Result of the query below is the column with numbers of visits at each of the doctors.

select doctor.id_doctor,concat(doctor.name,' ',dostor.surname) as sur_name, count(reg.id_position) as number_of_positions
from reg,doctor
where doctor.id=reg.id_doctor and reg.data_of_visit between '2003-11-20' and '2003-11-21'
group by reg.id_doctor

The purpose of new query is matching the mostly visited docot's name.

Thank You for every advice,
blazej
Reply With Quote
  #2 (permalink)  
Old 11-23-04, 07:31
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
So your result is only one row with the doctor who was visited most between those dates?

What version of mysql are you running?
Reply With Quote
  #3 (permalink)  
Old 11-23-04, 07:49
bjozefiak bjozefiak is offline
Registered User
 
Join Date: Nov 2004
Posts: 3
My result are rows in number of all doctors in database. Each row includes the columns with name and number of visits to each doctor, which is the result of my query.

I run WinMySQLadmin 1.4.
Reply With Quote
  #4 (permalink)  
Old 11-23-04, 14:36
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
windmysqladmin does not tell me what version of mysql it is. if it is 4.1 or newer then you can do sub queries. if it is older then you'd have to do a join.

Show a few rows from both tables and then show what you are asking for by posting some results in the joined table.
Reply With Quote
  #5 (permalink)  
Old 11-23-04, 19:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
to find out which version you're on, run this query --
Code:
select version()
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 11-24-04, 12:58
bjozefiak bjozefiak is offline
Registered User
 
Join Date: Nov 2004
Posts: 3
i work on 4.0.17-nt
Reply With Quote
  #7 (permalink)  
Old 11-24-04, 13:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
as far as your original problem is concerned (the "mostly visited" doctor), you can simply sort the result from the query you currently have, and use LIMIT --
Code:
select doctor.id_doctor
     , concat(doctor.name,' ',dostor.surname) 
             as sur_name
     , count(reg.id_position) as number_of_positions
  from doctor
left outer
  join reg
    on doctor.id
     = reg.id_doctor
   and reg.data_of_visit between '2003-11-20' and '2003-11-21' 
group 
    by doctor.id_doctor
     , concat(doctor.name,' ',dostor.surname) 
order 
    by number_of_positions  desc      
limit 1
note i've changed it to a LEFT OUTER JOIN in case there are any doctors without regs, although in this particular query it wouldn't really make much difference, because you want the highest number anyway
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On