dlite922 1,584
Recognized Expert Top Contributor
hey fellas (and ladies)
I need help with making a query.
My tables are: (Simplified) case:
id
violatorID
number violator:
id
name trial:
id
caseID
date
A Case can have Multiple trials with different dates.
I need a query that gets returns the following information
caseID, caseNumber, violatorName, and the FIRST trial date.
So i need distinct cases, but it should return the earliest trial date. If there's on in March and one in July, it should return the one in March.
MY ATTEMPT: -
-
SELECT c.id as NUM, c.caseNumber, v.firstName, v.lastName, t.courtDate
-
FROM `case` as c, violator as v, trial as t
-
WHERE c.violatorID = v.id AND t.CaseID = c.id
-
GROUP BY c.id;
-
-
the above returns the last trial date (in above example, the one in July)
Then i tried this: -
-
SELECT c.id as NUM, c.caseNumber, v.firstName, v.lastName, t.courtDate
-
FROM `case` as c, violator as v, trial as t
-
WHERE c.violatorID = v.id AND t.CaseID = c.id
-
ORDER BY t.courtDate
-
GROUP BY c.id;
-
-
-
//and got...
-
-
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY c.id' at line 1
-
-
-
can't use Order By and Group By together? at least in this instance i can't.
any tips much appreciate it.
for the record, I know violator should have caseID, instead of vice versa.
1 4898 code green 1,726
Recognized Expert Top Contributor
can't use Order By and Group By together? at least in this instance i can't
No, you've just got them the wrong way around.
GROUP BY has to be before ORDER BY
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: DBNovice |
last post by:
I have a database that keeps records on the issue and failure of an item.
Currently, the database is poorly desisned; therefore I'm performing queries
to break the data into normalized tables and attempting to perform a "left
join" query to build a cross-reference table.
The left join query is currently taking nearly 2 hours for MySQL to process,
using Navicat as a front-end. My system specs are 1.4Mhz Pentium Processor
with 1GB of RAM...
|
by: Paul Bramscher |
last post by:
Here's one for pathological SQL programmers.
I've got a table of things called elements. They're components, sort of
like amino acids, which come together to form complex web pages -- as
nodes in trees which form parent-child relationships, sort of like
newsgroups. For example, the parent_id field points to another element.
Indent_level is there for denormalization purposes, to avoid costly
recursive issues in querying. The...
|
by: signaturefactory |
last post by:
I am trying the following query in and oleDbCommand:
SELECT PartLocations.LocationName, Sum(PartsJournal.Quantity) AS
SumOfQuantity, PartsJournal.PartsLotNumber
FROM PartLocations INNER JOIN PartsJournal ON PartLocations.LocationID
= PartsJournal.LocationID
GROUP BY PartLocations.LocationName, PartsJournal.PartsLotNumber,
PartsJournal.PartNumber, PartsJournal.LocationID
HAVING (((Sum(PartsJournal.Quantity))>0) AND...
|
by: Pete |
last post by:
Before I get started with the question, does anyone have a (single)
good book recommendation for database design? Not an Access-specific
book, but something geared toward helping me figure out *what the user
wants*. I've had brief formal education about data flow diagramming,
but I'm looking for ... more, now that I'm actually running into
problems I think stem from the fact that my users can't explain what
they need done, compounded by...
|
by: ravi |
last post by:
I have created the following interest to calculate the interest for
the following currency pairs. I have tried to combine them in macros
using conditions but the next query that is run in the macro ends up
deleting the previous interest value that has been generated by the
query. For example if query 1 is run on the table with currency pair
USD/CHF then the interest will be updated without any problem but if
there is another entry in the...
| |
by: ED |
last post by:
I am attempting to to write a query that has a numerous nested IIf
statements. The problem that I am having is that it is to long of a
query to be built in design mode and when I build it in sql mode after
a certain point it give me the error message that the expression is to
complex. Below is the sql code that I am using (this works so far,
anything added to the code will give me the to complex error message.)
SELECT .WONUM, .,...
|
by: comp_databases_ms-sqlserver |
last post by:
This post is related to SQL server 2000 and SQL Server 2005 all
editions.
Many of my stored procedures create temporary tables in the code. I
want to find a way to find the query plan for these procs
Repro
--***********************************
use pubs
go
CREATE PROCEDURE Test @percentage int
|
by: djflow |
last post by:
Hi!
II was wondering if you can help me with SQL query..
Below 7 separated select query works fine(only when they are retrieved separately)
But I want to combined them together and so that i can make report from my database on the one sheet rather than querying each select statement ( I will use MS Query from the Excel)
=========================================================
1)
select convert(varchar, create_date_time, 112) as Date,...
|
by: mgsn |
last post by:
I Have This this Query
---------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc .
@userId int=null, -- filter: user id. overrides custid when supplied
@custId int=null, -- filter: customer id
@vcsId int=null, -- filter: status
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |