Two tables - customer (id,name) = {
-
'1','ABC';
-
'2','DEF';
-
'3','GHI'
-
}
- images (id,customer_id,subscription_id,imageURL) = {
-
'1','1','123','abc123.jpg';
-
'2','2','456','asdjkl.png';
-
'3','3','456','asad.gif';
-
}
I want to get the customer.name, images.id, and images.imageURL from the two tables. But,
the subscription_id should be '456'
AND
Join on customer id.
The query I am using is,
SQL = "Select c.name,i.id,i.imageURL from customer c LEFT JOIN images i ON c.id=i.customer_id WHERE i.subscription_id='456'"
What I need is - (customer.name, images.id, imageURL)
-
{ABC,1,NULL},
-
{DEF,2,'asdjkl.png'},
-
{GHI,3,'asad.gif'}
But it is returnning the last 2 rows as the WHERE clause is filtering the first ROW. But, I need NULL for the first row.
It is because I want to get the images of all the customers when the subscription is '456' if the subscription is something else then NULL should be returned.
Should I use something else instead of LEFT JOIN or what ?
any help
Use a CASE statement in the SELECT part rather than a WHERE condition.
Something like: -
CASE subscription_id
-
WHEN 456 THEN imageURL
-
ELSE null
-
END
Hope this helps!
2 1513
Use a CASE statement in the SELECT part rather than a WHERE condition.
Something like: -
CASE subscription_id
-
WHEN 456 THEN imageURL
-
ELSE null
-
END
Hope this helps!
@Coldfire
Obviously, you will get the imageURL field as null as you've applied LEFT JOIN..
Instead you should use INNER JOIN which will yield even more better results
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
To build a grid, all the distinct rows from T1 are required,
and only those from T2 which fall btn 2003-09-11 and 2003-09-18.
In the following example:
A is included because it is within the date...
|
by: Soefara |
last post by:
Dear Sirs,
I am experiencing strange results when trying to optimize a LEFT JOIN
on 3 tables using MySQL.
Given 3 tables A, B, C such as the following:
create table A (
uniqueId int not...
|
by: Leif Wessman |
last post by:
Hi!
Please have a look at the following query:
SELECT BOOKS.ISBN, BOOKS.TITLE, IMAGES.WEIGHT, IMAGES.WIDTH
FROM BOOKS
LEFT JOIN IMAGES ON BOOKS.ISBN = IMAGES.ID
WHERE MATCH(BOOKS.TITLE)...
|
by: David Boone |
last post by:
Please excuse the newbie questions, but I'm fairly new to Access
though familiar with databases in general (experience with MySQL and
PostgreSQL).
The basic idea is that there is table of...
|
by: deko |
last post by:
SELECT tblTxAcct.TxAcctName, tblTxType.TxTypeName,
Nz(qryTxAcctListCt.TxCount, 0) AS TxCt
FROM (tblTxAcct INNER JOIN tblTxType ON
tblTxAcct.TxType_ID=tblTxType.TxType_ID) LEFT JOIN qryTxAcctListCt...
|
by: phillip.s.powell |
last post by:
I have to produce a query to obtain a single record, however, the
tables I work with have a very strange relationship:
Table: student
Fields:
id
first_name
last_name
email
school_type_id...
|
by: mlarson |
last post by:
I have a program that worked fine then they needed to be able to also see the empty cells (inmate cells) on a housing unit when they ran the query. So what I had to do was take two tables and...
|
by: sesmap |
last post by:
I am not certain if I set this up correctly - all help would be appreciated:
SELECT .ACCOUNTID, .PUBCODE, .NAME, .PIATYPE, .FOD, .SUBSLNGTH, .RATECODE, .CURRENTBAL, .EOGDATE, .TELEPHONE,...
|
by: imnewtoaccess |
last post by:
Hello everybody,
I have two tables : ac_online_scanned_tkts_1 and TK_IMPORT_TICKET1.
Both have external barcodes of tickets, but not all of them in ac_online_scanned_tkts_1 table exist in...
|
by: knkk |
last post by:
Please see this:
WARNING Error while executing query:
select event_type, EventId, VenueId, Price, Schedule, ev.startDate, ev.endDate, events.name eventname, movies.name moviename from...
|
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: 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,...
|
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...
|
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...
|
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...
|
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...
| |