473,378 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SQL doubt..

15
Expand|Select|Wrap|Line Numbers
  1. Table1: Produtos
  2. Codprod, Descricao
  3. 1          , Product One
  4. 2          , Product Two
  5.  
Expand|Select|Wrap|Line Numbers
  1. Table2: Ped_det
  2. codprod, codprod2, etc etc
  3. 1          ,  2
  4. 2          ,  1
  5.  


Expand|Select|Wrap|Line Numbers
  1. select b.descricao as "Código_1", b.descricao as "Código_2", quant as "Qtd", tam as "Tamanho", preco as "Preço", borda as "Borda", obs as "Observações" 
  2. from ped_det a , produtos b
  3. where a.codprod = b.codprod 
  4. and a.codprod2 = b.codprod and codped =   2

the output i want is like this:
Expand|Select|Wrap|Line Numbers
  1. Product One, Product Two
  2. Product Two, Product One
  3.  
what i`m getting is something likt this:
Expand|Select|Wrap|Line Numbers
  1. Product One, Product One
  2. Product Two, Product Two
  3.  
thanks for the help
May 23 '09 #1
2 1453
Atli
5,058 Expert 4TB
Hi.

Are you sure those are the correct values?

I ask because your query asks for rows where the `ped_det` table has the same value for both `codprod` and `codprod2`, but in the list of rows you gave us, no row has the same values twice.

It should be giving you an empty set.

Another thing; in your SELECT query, the first two columns you list (Código_1 and Código_2) are in fact the same column of the same table (b.descricao), and will therefore always be the same value.

If you want it to return values from two different rows in the same table, you will have to either subquery them separately or join the table twice.
For example (using subqueries):
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.   (SELECT `descricao` FROM `produtos`
  3.    WHERE `codprod` = o.`codprod`) AS 'First',
  4.   (SELECT `descricao` FROM `Product`
  5.    WHERE `codprod` = o.`codprod2`) AS 'Second'
  6. FROM `ped_det` AS o;
May 24 '09 #2
nexusbr
15
THanks!!!!! it worked!!

:)
May 24 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Guilherme Pinto | last post by:
Hello. I am reading the book written by Bjarne Stroustrup called " The C++ Programming Language - Special Edition" and had a doubt which a think is really important to distinguish between the...
138
by: ambika | last post by:
Hello, Am not very good with pointers in C,but I have a small doubt about the way these pointers work.. We all know that in an array say x,x is gonna point to the first element in that...
4
by: dam_fool_2003 | last post by:
I am just a beginner in tree data – struct. I have this little doubt. Left node ‘weights' lesser than the right one. I have seen, so far it is algorithm implementations. But why not vice-versa that...
20
by: maadhuu | last post by:
firstly, i am thankful to all those who answered the 1st set of doubts. And i am not yet enlightened to that extent , coz ' i keep getting doubts. is the following defined in the language ?? int...
3
by: SMG | last post by:
Hi All, It might be a silly doubt, but it is a doubt.... I am using form authentication for my website, now my web application is gonna be deployed on two web servers with Load Balancing...
77
by: muttaa | last post by:
Hello all, My doubt is going to be so primitive that i ask you all to forgive me beforehand.... Here's the code snippet: int main() { int x=5;
11
by: Bob Nelson | last post by:
I don't remember seeing the term ``doubt'' used much in c.l.c. back in the 90's. When did this word become nearly synonymous with ``question'' or ``query'' and does it have static duration?
122
by: ivan | last post by:
hi all, if I have: if(A && B || C) which operation gets executed first? If I remeber well should be &&, am I correct? thanks
5
by: Paulo | last post by:
Hi, I have a RadioButtonList and I need to do some verifications on a "OnChange" event on client... because on classic asp/html I just add a "onChange" event on <input type="radio" onChange="">,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.