Jump to content

Need help with SQL query


Recommended Posts

Hi.Could someone here help me making a query that shows result like this:Partnersname1 phonenumbername2 phonenumbername3 phonenumbername4 phonenumbername5 phonenumbername6 phonenumberAdministratorsname7 phonenumbername8 phonenumbername9 phonenumbername10 phonenumbername11 phonenumbername12 phonenumberThe part of showing the name and phone nr fields is not difficult, but having them grouped under company like above I don't know how to acheive.If you had 3 fields called name, phone and company - how would you write your query to acheive a result as above? :-)Regards.

Link to post
Share on other sites

Order by company then name, and use the scripting language to figure out what the last company is that you saw, and if the current company is different then print the company name before you print the record.

Link to post
Share on other sites
Order by company then name, and use the scripting language to figure out what the last company is that you saw, and if the current company is different then print the company name before you print the record.
Hi, and thanks a lot for answeringIf i use this:Select name, phone, companyFrom ProfileDBOrder by companyThis will give me the comany on each line also. I need the company to be the header "header". Like this (here Partners and Administrators are company):Partnersname1 phonenumbername2 phonenumbername3 phonenumbername4 phonenumbername5 phonenumbername6 phonenumberAdministratorsname7 phonenumbername8 phonenumbername9 phonenumbername10 phonenumbername11 phonenumbername12 phonenumberMy code will give me this on each line:name, phone nr, company Is it possible to make the company the "header" and then list all users from the same company under it in pure sql?
Link to post
Share on other sites
This will give me the comany on each line also.
Yes, I know. But just because the company field is in the record doesn't mean you need to print it. You need to keep track of what the last company that you printed is and, when it changes, print the new company out and then print the rest of the record like normal. You only want to print the company before the first record that uses that company. Which means you need to keep track of what the last company is that you printed and only print the company when you get to a new one.All records in a SQL result set have the same fields. You can't have 1 record in a result set have only a company field, and another record have a different set of fields. They all have the same fields, so you need to keep track of which company you're on and figure out when you see a new company that you need to print.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...