I have two tables, table a and table b.
I do : - select *
-
from a
-
inner join b
-
on b.some = a.something
-
where b.another = somevalue
How can I put another WHERE to sort my data but for an attribute from table a.
When I put it after the last WHERE it doesn't bring me any results.
Thanks
9 1846
I have two tables, table a and table b.
I do :
select *
from a
inner join b
on b.some = a.something
where b.another = somevalue
How can I put another WHERE to sort my data but for an attribute from table a.
When I put it after the last WHERE it doesn't bring me any results.
Thanks
Can you post the query that didn't work?
You only put one where and separate the conditions with an and if you want to add additional filtering. For sorting you use order by not a where clause.
Elboratingr 035198x's answer with examples
If you want to add another WHERE condition, simply add AND and the condition - select * from a
-
inner join b
-
on b.some = a.something
-
where b.another = somevalue
-
AND a.comecolumn = 'some value'
This is the answer to your adding order by (sorting the results) - select * from a
-
inner join b
-
on b.some = a.something
-
where b.another = somevalue
-
ORDER BY a.somecolumn
But still we want to see which query you have tried.
- SELECT * Person.FullName, Person.BirthDate, Person.Address
-
FROM Partners
-
INNER JOIN Person
-
ON Person.PartnerID = Partners.Customer and Person.BirthDate > '1980-10-05'
-
where Partners.Producer = '158'
That's the query. If I don't use the last line (where Partners.Producer = '158'), it returns me results. But when I use a last where for any property of table Partners, the query just runs and runs... no results.
Thank you for your time.
SELECT * Person.FullName, Person.BirthDate, Person.Address
FROM Partners
INNER JOIN Person
ON Person.PartnerID = Partners.Customer and Person.BirthDate > '1980-10-05'
where Partners.Producer = '158'
That's the query. If I don't use the last line (where Partners.Producer = '158'), it returns me results. But when I use a last where for any property of table Partners, the query just runs and runs... no results.
Thank you for your time.
I suppose you have read the responses given above?
Thanks for your quick responses.
I am trying the way, you told me, but it doesn't work.
Maybe it's a database problem.
Kinldy use appropriate code tags when posting code/syntax. Please follow this site's Posting Guidelines when posting questions or answers.
You can not write the query like - SELECT * Person.FullName, Person.BirthDate...
You must have to use comma to separate column names in the SELECT. - SELECT *, Person.FullName, Person.BirthDate...
You can write your query as below too (I have moved Person.BirthDate > '1980-10-05' to WHERE clause) - SELECT * FROM Partners
-
INNER JOIN Person
-
ON Person.PartnerID = Partners.Customer
-
WHERE Person.BirthDate > '1980-10-05' AND Partners.Producer = '158'
Make sure you have the records where Producer = '158' and the date is greater than '1980-10-05'.
Because of many records I have in the database, it takes too long to bring results and most times it just crashes.
Question can be closed.
Thank you for your answers and your time.
Because of many records I have in the database, it takes too long to bring results and most times it just crashes.
Consider optmizing your query by creating indexes on Person.BirthDate and Partners.Producer. This will definetly reduce your query time.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ike |
last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL
4.0.20-standard. Thus, in trying to expedite the query, I am trying to set
indexes in my tables.
My query requires four...
|
by: Prem |
last post by:
Hi,
I am having many problems with inner join. my first problem is :
1) I want to know the precedance while evaluating query with multiple
joins.
eg.
select Employees.FirstName,...
|
by: Nathan |
last post by:
I have an application that uses an Access database to
gather information on students' test scores. In the
database there are three tables which are joined by one-
to-many relationships: ...
|
by: dmonroe |
last post by:
hi group --
Im having a nested inner join problem with an Access SQl
statement/Query design. Im running the query from ASP and not usng the
access interface at all. Here's the tables:
...
|
by: MP |
last post by:
Hi
trying to begin to learn database using vb6, ado/adox, mdb format, sql
(not using access...just mdb format via ado)
i need to group the values of multiple fields
- get their possible...
|
by: Zeff |
last post by:
Hi all,
I have a relational database, where all info is kept in separate tables
and just the id's from those tables are stored in one central table
(tblMaster)...
I want to perform a query, so...
|
by: Chamnap |
last post by:
Hello, everyone
I have one question about the standard join and inner join, which one
is faster and more reliable? Can you recommend me to use? Please,
explain me...
Thanks
Chamnap
|
by: teneesh |
last post by:
Here I have a code for a view that has been created by a developer on my team. I am trying to use the very same code to create a view for a different formid/quesid. But I cannot figure out how this...
|
by: MATTXtwo |
last post by:
I have this store procedure to select data from table with join like this...SELECT tblPeribadi.Personel_No, tblPeribadi.Nama,tblCompany.Keterangan as Company_Code, tblPeribadi.Jawatan,...
|
by: AXESMI59 |
last post by:
I created a query in the Access Query Builder that I modified to use with VBA Code so I could reuse it for any record I choose. The one that I created with the Access Query builder works beautifully...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
| |