This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
It could be because what you are getting is really what is in the database, and you are mistaken about what you think is in the database. Or it could be that your code which extracts data from the database is wrong.
Joined: Jun 22, 2012
I am running the query in the DB itself.. I mean I am not using code.
When I run select public.order.ORDER_ID from public.person,public.order where public.person.person_id=public.order.person_id
I get the number of the order but when I add the nextg two queries I get ORDER_ID but it is empty
select public.order.ORDER_ID from public.person,public.order where public.person.person_id=public.order.person_id and public.person.first_name='Dura'
SELECT public.order.ORDER_ID FROM public.person
INNER JOIN public.order ON public.person.person_id=public.order.person_id
I just created two tables person and order on my PostgreSQL database, inserted records like your person/order examples, and ran the following queries, which both returned a single row with the expected Order ID:
The query syntax is correct, so the problem must be in how it's finding (or not finding) the data. One problem could be if you have trailing spaces on your names e.g. "Dura " instead of "Dura". You can check for this by using TRIM on the name columns:
If this query works, then you know there are rogue spaces in your first_name column, so you need to trim these off when inserting/updating your data. Also, make sure you use VARCHAR (or VARCHAR2) and not CHAR as the data-type for your character columns, as some databases fill CHAR columns with spaces without you realising it.
and paste it into the tool you're using to test your SQL code, you'll find it doesn't return any records there either. That's because your table doesn't contain any records with the string "args" in the first_name column.