this is my query -
select distinct * from
-
(select distinct city,itm__code,barcode1 from bx_itembarcodemaster
-
where city = 'jhb'
-
and (barcode1 is not null and bqty1 is not null)
-
) jhb
-
left join
-
(
-
select distinct city,itm__code,barcode1 from bx_itembarcodemaster
-
where city = 'cpt'
-
and (barcode1 is not null and bqty1 is not null)
-
) cpt on cpt.itm__code = jhb.itm__code
-
left join
-
(
-
select distinct city,itm__code,barcode1 from bx_itembarcodemaster
-
where city = 'dbn'
-
and (barcode1 is not null and bqty1 is not null)
-
) dbn on dbn.itm__code = jhb.itm__code
-
and this is the result set -
JHB 0-16040 0-16040 CPT 0-16040 0-16040 DBN 0-16040 0-16040
-
JHB 0-16040 0-16040 CPT 0-16040 0-16040 DBN 0-16040 6002303714622
-
JHB 0-16040 0-16040 CPT 0-16040 6002303714622 DBN 0-16040 0-16040
-
JHB 0-16040 0-16040 CPT 0-16040 6002303714622 DBN 0-16040 6002303714622
-
JHB 0-16040 6002303714622 CPT 0-16040 0-16040 DBN 0-16040 0-16040
-
JHB 0-16040 6002303714622 CPT 0-16040 0-16040 DBN 0-16040 6002303714622
-
JHB 0-16040 6002303714622 CPT 0-16040 6002303714622 DBN 0-16040 0-16040
-
JHB 0-16040 6002303714622 CPT 0-16040 6002303714622 DBN 0-16040 6002303714622
-
Its in multiples of 4 at first then 2 then 1 even thought there should technically only be 2 lines returned
WHat am i doing wrong?
5 1315 ck9663 2,878
Recognized Expert Specialist
Your LEFT JOIN returns all rows from your quest query regardless if there are matching rows on your right query.
Happy Coding!!!
~~ CK
i tried just normal joining aswell, but it does the same thing
ck9663 2,878
Recognized Expert Specialist
Have you tried INNER JOIN ?
Happy Coding!!!
~~ CK
Tried all the joins its gives the same result
ck9663 2,878
Recognized Expert Specialist
Will this work? -
-
select distinct city,itm__code,barcode1
-
from bx_itembarcodemaster
-
where city in ('jhb','ctp','dbn') and
-
(barcode1 is not null and bqty1 is not null)
-
Happy Coding!!!
~~ CK
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Agoston Bejo |
last post by:
Version: Oracle 8.1.7. (I know it's prehistoric, but I am forced to work
with it. Nevertheless, I'm curious if this is only a bug of this version or
I'm wrong somewhere about SQL itself.)
Take a look at this query:
-----------------------
SELECT * FROM
(
|
by: netpurpose |
last post by:
I need to extract data from this table to find the lowest prices of
each product as of today. The product will be listed/grouped by the
name only, discarding the product code - I use SUBSTRING(ProductName,
1, CHARINDEX('(', ProductName)-2).
I can get this result, but I had to use several views (totally
inefficient). I think this can be...
|
by: Diamondback |
last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has
descriptive information about the widgets while the VERSIONS table
contains IDs relating to different iterations of those widgets over the
years. The idea is that from any widget in the database you can look
forward and backward to see different versions of the widget through...
|
by: Steven D.Arnold |
last post by:
I have a query which does not use column indexes that it should use. I
have discovered some interesting behaviors of Postgres which may
indicate a bug in the database's query planning.
Take a look at the query below. There is a btree index on both
m.account_id and a.account_id. Query (1) does not use the index on the
messages table,...
|
by: Nicolae Fieraru |
last post by:
Hi All,
I have a query, Select Count(BoolField) from tblMyTable, Where BoolField =
true.
If I run the query by itself, it returns the number of true records
I want to use the result of that query in my VBA code, like this:
If (result of the query > 0) then
do something
| |
by: lakshmi |
last post by:
Hi all
I'm trying to traverse through the results from a query
that returns more than 1 row. The data reader reads only
the first row. The following code doesn't work. Let me
know what's wrong.
do
{
while(reader.read)
{
x += y;
|
by: Marc DVer |
last post by:
As a simple example, say there is table 'namelist' with column 'names'
as char(20). I would like to do something akin to:
select namelist.names as mynames, left(mynames,2) as initials;
In this example, I could just do left(namelist.names,2), but in more
complex cases a value retrieved may have had a more complex logic behind
it, e.g., if...
|
by: Cuthbert |
last post by:
After compiling the source code with gcc v.4.1.1, I got a warning
message:
"/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the
'gets' function is dangerous and should not be used."
Could anybody tell me why gets() function is dangerous??
Thank you very much.
Cuthbert
|
by: DanWeaver |
last post by:
I am assigning a profile variable based on the conents of a text box
when a button is pressed- this is then used as a search term to
populate a list box- all controls are in same ajax update panel- how
can I update the profile variable before the listbox gets populated -
ie assign the variable prior to the sql call (as the sql query should...
|
by: billchalmers |
last post by:
I am using sql 2005 express and I have a strange proble, when I execute a stored procedure from the query window I get the results I expect, but when I execute it from an asp page then I get a slightly different result.
My stored procedure accepts a start date and a Day of week, it then gets the date of the next date that falls on that day, it...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |