473,699 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble with GROUP BY ...

4 New Member
SELECT TOP 25 *
FROM new_ticket
WHERE group_num NOT IN (SELECT TOP 75 no FROM new_ticket ORDER BY no DESC)
ORDER BY group_num DESC


I am using the above method to get pagination with PHP Script.
It is running on MS SQL Server 2005 Express Edition.

After long been trying, I haven't found a way to get them grouped.
I modified very last line "GROUP BY group_num" and didn't work!

Is anyway this can be grouped and arrayed DESC order?
I need someone very Smart and save me!!
Sep 13 '07 #1
7 2373
ck9663
2,878 Recognized Expert Specialist
SELECT TOP 25 *
FROM new_ticket
WHERE group_num NOT IN (SELECT TOP 75 no FROM new_ticket ORDER BY no DESC)
ORDER BY group_num DESC


I am using the above method to get pagination with PHP Script.
It is running on MS SQL Server 2005 Express Edition.

After long been trying, I haven't found a way to get them grouped.
I modified very last line "GROUP BY group_num" and didn't work!

Is anyway this can be grouped and arrayed DESC order?
I need someone very Smart and save me!!

am not a very smart but i can try to help you...

Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 25 group_num
  2. FROM new_ticket 
  3. WHERE group_num NOT IN (SELECT TOP 75 no FROM new_ticket ORDER BY no DESC) 
  4. GROUP BY group_num 
  5. ORDER BY group_num
  6.  
that is, if group_num is all you need. as a rule of thumb, you have to include in GROUP BY all non-aggreate functions in your select list
Sep 14 '07 #2
Daniel Lee
4 New Member
Thanks for your help. But, that's not exactly what I want.
There are more columns other than group_num and I'd like to display all other colunms based on the group_num displayed.

What I want to see is that other columns lined up according to the group numbers resulted from your SQL query.

Thanks



am not a very smart but i can try to help you...

Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 25 group_num
  2. FROM new_ticket 
  3. WHERE group_num NOT IN (SELECT TOP 75 no FROM new_ticket ORDER BY no DESC) 
  4. GROUP BY group_num 
  5. ORDER BY group_num
  6.  
that is, if group_num is all you need. as a rule of thumb, you have to include in GROUP BY all non-aggreate functions in your select list
Sep 14 '07 #3
ck9663
2,878 Recognized Expert Specialist
Thanks for your help. But, that's not exactly what I want.
There are more columns other than group_num and I'd like to display all other colunms based on the group_num displayed.

What I want to see is that other columns lined up according to the group numbers resulted from your SQL query.

Thanks

if you don't have duplicate group_num then this would be it

Expand|Select|Wrap|Line Numbers
  1.       SELECT TOP 25 *
  2.       FROM new_ticket
  3.       WHERE group_num NOT IN (SELECT TOP 75 no FROM new_ticket ORDER BY no DESC)
  4.       ORDER BY group_num
Sep 14 '07 #4
Daniel Lee
4 New Member
Your worst guess was right. There are duplicate group_nums
I tried JOIN but didn't work.

id , group_num , issue
1 , 1 , A
------------------------------------------------------
2 , 1 , B
------------------------------------------------------
3 , 2 , C
------------------------------------------------------
4 , 2 , D
------------------------------------------------------



I want to see somthing like this.
id , group_num , issue
-------------------------------------
1 , 1 , A
--------------------------------------
3 , 2 , C
-------------------------------------



if you don't have duplicate group_num then this would be it

Expand|Select|Wrap|Line Numbers
  1.       SELECT TOP 25 *
  2.       FROM new_ticket
  3.       WHERE group_num NOT IN (SELECT TOP 75 no FROM new_ticket ORDER BY no DESC)
  4.       ORDER BY group_num
Sep 14 '07 #5
ck9663
2,878 Recognized Expert Specialist
Your worst guess was right. There are duplicate group_nums
I tried JOIN but didn't work.

id , group_num , issue
1 , 1 , A
------------------------------------------------------
2 , 1 , B
------------------------------------------------------
3 , 2 , C
------------------------------------------------------
4 , 2 , D
------------------------------------------------------



I want to see somthing like this.
id , group_num , issue
-------------------------------------
1 , 1 , A
--------------------------------------
3 , 2 , C
-------------------------------------

what's the factor to consider 1,1,A instead of 1,1,B ? that would affect your query. if this is a troubleshooting ticket table, are you planning to get the first record or the latest one?
Sep 14 '07 #6
Daniel Lee
4 New Member
I am migrating MYSQL to MS-SQL. MYSQL script works fine
when use * with GROUP BY group_num and it shows all fileds in each row.
but Mssql doesn't support SELECT * and GROUP BY one_column.

id , group_num , issue, customer_name
1 , [1] , Wiper , john
------------------------------------------------------
2 , [3], Transmission , bill
------------------------------------------------------
3 , [3] , Engine , mike
------------------------------------------------------
4 , [3] , Engine , david
------------------------------------------------------


I want to see somthing like this.
As long as group_num shows only unique number, that will eliminate my headaches. The 2nd row could be 2 ,[3] Engine, david. As long as only one group_num appears on the list page that will be okay.

1 , [1] , Wiper , john
------------------------------------------------------
2 , [3] , Transmission , bill
------------------------------------------------------



what's the factor to consider 1,1,A instead of 1,1,B ? that would affect your query. if this is a troubleshooting ticket table, are you planning to get the first record or the latest one?
Sep 15 '07 #7
ck9663
2,878 Recognized Expert Specialist
I am migrating MYSQL to MS-SQL. MYSQL script works fine
when use * with GROUP BY group_num and it shows all fileds in each row.
but Mssql doesn't support SELECT * and GROUP BY one_column.

id , group_num , issue, customer_name
1 , [1] , Wiper , john
------------------------------------------------------
2 , [3], Transmission , bill
------------------------------------------------------
3 , [3] , Engine , mike
------------------------------------------------------
4 , [3] , Engine , david
------------------------------------------------------


I want to see somthing like this.
As long as group_num shows only unique number, that will eliminate my headaches. The 2nd row could be 2 ,[3] Engine, david. As long as only one group_num appears on the list page that will be okay.

1 , [1] , Wiper , john
------------------------------------------------------
2 , [3] , Transmission , bill
------------------------------------------------------
how's this:

Expand|Select|Wrap|Line Numbers
  1. select * from new_ticket a inner join 
  2. (select group_num, max(id) as id from new_ticket group by group_num) b on a.group_num = b.group_num and a.id = b.id
  3. where <that condition you have to check for the top 75% or something>
  4.  
Sep 15 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2583
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i access the recordset it displays the results, what the real issue is that the entry is not made into the database even though i use the Update command and i have also tried the BeginTrans and CommitTrans nothign seems to work and i am unable to...
6
1289
by: Jeremy Cowles | last post by:
Hi all, Disclaimer: This app is actually written in a different language, but I have much respect for this group & wanted to get your input so please ignore any minor syntactical errors. I have a program that needs to perform an action: Inventory Adjustment. This action takes several arguments: Data to describe which item to adjust:
7
4213
by: laclac01 | last post by:
So I am converting some matlab code to C++. I am stuck at one part of the code. The matlab code uses fread() to read in to a vector a file. It's a binary file. The vector is made up of floats, which in matlab is 32 bits. How do I get this binary file in to floats in c++? I try reading the file using the ifstream>>myFloat. But nothing ever goes in to the float. So the closest I have come is having 4 unsigned char store the binary data....
1
1154
by: mr_burns | last post by:
hi there, Ive been having a few problems recently with this group. Im not sure if any of the other groups have been giving me trouble but recently this one has a couple of times, when attempting to reply, given me the message 'Unable to retrieve message rccharles-80ED6A.14593808012005@individual.net'. Has anybody else had any similar problems?
10
2040
by: Alejandro Castañaza | last post by:
Hi. I'm writing a program, and I need to send confidential data through the network, so I decided to use encryption, using the System.Security.Cryptography namespace. I'm using the sockets for the network communications, and the program first does a key exchange, with the asymetric cipher classes, to get a new key for the symmetric cipher. My problem is, that although I have checked that the two points get to the same key and...
1
1867
by: Hervé Piedvache | last post by:
Dear all, I have a trouble with the pam authentification for PostgreSQL. I have add in the pg_hba.conf the good line ... and I have create a /etc/pam.d/postresql file which contains : auth required pam_unix.so nullok_secure account required pam_unix.so
1
1628
by: Jozef | last post by:
Hello. I'm having trouble creating a blank solution (and ASP.net web application) from my laptop. I own the server (in fact it's sitting right next to me) and have added the URL to the trusted sites on my laptop. Here are the details; This is what I'm selecting from the start page.... >Add New Blank Solution >Visual Basic Projects,
0
1846
by: harry12 | last post by:
Hello- I'm fairly new at using Microsoft Access and I'm having trouble getting a couple of things to work in my database. The first is that I have yet to find a way to get an append query to add only new records and not all the records. As an example, this query filters a list of property owners for duplicates and then appends to a table where they are assigned autonumer IDs. The problem is that I'm constantly entering new owners in and...
6
2033
by: Pep | last post by:
Firstly, I'm not sure if this is the right group for this query, so please forgive me if I am wrong. My problem is that most users I distribute my software to cannot install it on their systems due to not having the correct administrator rights. I'm perplexed over this as I cannot reasonably ask corporations to allow the local secretary to have admin or power user rights just to install my software. My software is intended for user...
24
4202
by: GesterX | last post by:
First of all I'm new to this site but it certainly looks like a place that i will be visiting more often! Onto my problem. I am creating a Hotel Bussiness project in java using BlueJ The classes are as follows: Hotel - Deals with the major functions of the hotel (i.e guests booking in, finding rooms etc.) Room - Used to decide whether a room has a sea view and stores the guest that is in the room. Occupier - For information about the...
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.