Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

General T-SQL question Help!!!

$
0
0

This is my problem :

It involves 2 tables; Tickets and Ticket_Characs

Tickets (this table has more columns, but only need these two)

* ticket_id

* package_id (foreign key from other table)

Ticket_Characs

*ticket_id (this is a foreign key from Tickets table and also a primary key with the name field)

*name

*value

One ticket can have different characs

ex: Ticket 1 -------charac value: very good

                            charac value: good

                            charac value: bad

ex: Ticket 2 -------

                            charac value: good

                            charac value: bad


ex: Ticket 3 ------- charac value: very good

                             charac value: good


I need to find the tickets (ticket_id) that are from specific packages (the package_id is foreign key in the table Tickets)

AND does not include the charac value: bad,

in this case will be Ticket 3

I thought.. very easy and did this: 

SELECT DISTINCT TH.master_ticket_id,TH.package_id,TH.package_name,TC.name,TC.value
FROM ticket_header TH
     JOIN ticket_characs TC ON TH.ticket_id = TC.id
WHERE TH.merchant_id = 10 
      AND TH.package_id in (1571,1572,15173)
      AND TC.value NOT LIKE 'bad%'

but it comes the other tickets because they have other characs that are not: charac bad

Any help please, 

thanks in advance


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>