I am new to SQL and thus facing some problems in enhancing a SQL query.
There are two tables basically: one is ef_dat_app_ef_link and the other is ef_dat_lspd_machine_type_model
Here is the query I am talking about. I have added an inner join in the 10th line which is the base of all problems.
select country_isocode as country,
language_isocode as language, model_number,
machine_type_model_name model_name,machine_type_group_id,
machine_type_model_id, product_type_name product_type,
machine_type_model_id_to,filenet_link
from ef_dat_lspd_machine_type_model,
cross join ef_dim_lspd_country_language
left join ef_dat_lspd_model_country
using (machine_type_model_id, country_isocode)
inner join ef_dat_app_ef_link on (ef_dat_lspd_machine_type_model.lpmd_revenue_pid = ef_dat_app_ef_link.ef_product_revenue_pid)
where (ef_dat_app_ef_link.country_isocode='US' or ef_dat_app_ef_link.country_isocode='CA') and ef_dat_app_ef_link.language_isocode='en'
join ef_dat_lspd_product_type using (product_type_id)
left join ef_dat_lspd_model_relationship on (machine_type_model_id_from = machine_type_model_id)
where (discontinue_date is null or discontinue_date > sysdate) and
(announce_date is null or announce_date <= sysdate)
and (machine_type_model_id in (select machine_type_model_id from ef_dat_lspd_model_parts)
or not machine_type_model_id_to is null) order by machine_type_model_id
Below is the unchanged query which I am supposed to work on.
select country_isocode as country,
language_isocode as language,
machine_type_model_id,
product_type_name product_type,machine_type_model_id_to,
image_url
from ef_dat_lspd_machine_type_model cross join ef_dim_lspd_country_language
left join ef_dat_lspd_model_country using (machine_type_model_id, country_isocode)
join ef_dat_lspd_product_type using (product_type_id)
left join ef_dat_lspd_model_relationship on (machine_type_model_id_from = machine_type_model_id)
where (discontinue_date is null or discontinue_date > sysdate) and
(announce_date is null or announce_date <= sysdate) and
(machine_type_model_id in (select machine_type_model_id from ef_dat_lspd_model_parts) or >not machine_type_model_id_to is null)
order by machine_type_model_id
Now in the ef_dat_app_ef_link table there is a link with images,countrycode and languagecode and a revenueid and the other is ef_dat_lspd_machine_type_model which contains the image links and a few more columns. What I am trying to do is, create a query which shall replace pull up images from the ef_dat_app_ef_link table where the revenue id in this table is equal to the revenue id in the other table. A lot of columns come up when a table is searched by the revenue id, thats why i want to pull up a row which has language as 'en' and country as 'US' or 'CA'.
I have added an inner join statement to the same effect but it is consistently throwing a ORA00905 error for a missing keyword.
I have italicized the changes I have made. Sorry for such a bad representation of the code. I couldn't make head or tail of how to make it look better.
You added a WHERE clause smack dab in the middle of the existing query. You can't have more than one WHERE clause in a query, and you also can't place it in the middle of your table joins.
Merge the WHERE clause you added to the pre-existing one (indicated by the green arrow in the snapshot).